lib/active_regulation/containment.rb in active_regulation-2.2.4 vs lib/active_regulation/containment.rb in active_regulation-2.2.5

- old
+ new

@@ -4,11 +4,11 @@ include ActiveRegulation::Base included do attr_accessor :containment, :raw_containment - before_save :record_containment!, unless: -> (obj) { obj.raw_containment.nil? } + before_save :record_containment! after_initialize :set_containment! scope :contained, -> { where.not(contained_at: nil) } scope :uncontained, -> { where(contained_at: nil) } end @@ -34,17 +34,19 @@ end private def record_containment! - false_value = FALSE_VALUES.include?(containment) - true_value = TRUE_VALUES.include?(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." + 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 \ No newline at end of file