Module: DeepDirty
- Defined in:
- lib/deep_dirty.rb,
lib/deep_dirty/version.rb
Constant Summary collapse
- VERSION =
"1.0.2"
Class Method Summary collapse
Instance Method Summary collapse
-
#deep_changed? ⇒ Boolean
apply deep dirty check and then return ‘changed?`.
-
#deep_dirty_check ⇒ Object
Compare each attribute to it’s value before type cast and mark changes where detected.
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 |
# File 'lib/deep_dirty.rb', line 4 def self.included(base) base.class_eval do before_validation :deep_dirty_check end end |
Instance Method Details
#deep_changed? ⇒ Boolean
apply deep dirty check and then return ‘changed?`
11 12 13 14 |
# File 'lib/deep_dirty.rb', line 11 def deep_changed? deep_dirty_check changed? end |
#deep_dirty_check ⇒ Object
Compare each attribute to it’s value before type cast and mark changes where detected
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/deep_dirty.rb', line 17 def deep_dirty_check self.attributes.keys.each do |attr| next if attribute_changed?(attr) col = column_for_attribute(attr) uncast_value = read_attribute_before_type_cast(attr) recast_value = col.type_cast(uncast_value) unless recast_value == read_attribute(attr) changed_attributes[attr] = recast_value end end # This should never break validation true end |