lib/active_regulation/containment.rb in active_regulation-2.2.5 vs lib/active_regulation/containment.rb in active_regulation-2.2.6
- old
+ new
@@ -1,16 +1,10 @@
module ActiveRegulation
module Containment
extend ActiveSupport::Concern
- include ActiveRegulation::Base
included do
- attr_accessor :containment, :raw_containment
-
- before_save :record_containment!
- after_initialize :set_containment!
-
scope :contained, -> { where.not(contained_at: nil) }
scope :uncontained, -> { where(contained_at: nil) }
end
def contain!
@@ -27,32 +21,15 @@
def uncontained?
contained_at.nil?
end
- def to_containment
- I18n.t("active_regulation.containment.#{uncontained? ? :uncontained : :contained}")
+ def contained_at_or_time
+ uncontained? ? Time.now : contained_at
end
- private
-
- def record_containment!
- unless raw_containment.nil?
- false_value = FALSE_VALUES.include?(containment)
- true_value = TRUE_VALUES.include?(containment)
-
- if false_value || true_value
- self.contained_at = (false_value ? nil : Time.now)
- else
- raise ArgumentError,
- "Unknown boolean: #{containment.inspect}. Must be a valid boolean."
- end
- end
- end
-
- def set_containment!
- self.raw_containment = containment
- self.containment = contained? if containment.nil?
+ def to_containment
+ I18n.t("active_regulation.containment.#{uncontained? ? :uncontained : :contained}")
end
end
end
\ No newline at end of file