]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/concerns/redactable.rb
Convert lib files to model concerns
[rails.git] / app / models / concerns / redactable.rb
diff --git a/app/models/concerns/redactable.rb b/app/models/concerns/redactable.rb
new file mode 100644 (file)
index 0000000..ccf0490
--- /dev/null
@@ -0,0 +1,20 @@
+module Redactable
+  extend ActiveSupport::Concern
+
+  included do
+    scope :unredacted, -> { where(:redaction_id => nil) }
+  end
+
+  def redacted?
+    !redaction.nil?
+  end
+
+  def redact!(redaction)
+    # check that this version isn't the current version
+    raise OSM::APICannotRedactError if is_latest_version?
+
+    # make the change
+    self.redaction = redaction
+    save!
+  end
+end