Module: Multiplay::WasChanged
- Defined in:
- lib/multiplay/was_changed.rb
Class Method Summary collapse
Instance Method Summary collapse
- #attribute_before_save_change(attr) ⇒ Object
- #attribute_before_save_was(attr) ⇒ Object
- #attribute_was_changed?(attr) ⇒ Boolean
- #saved_changes ⇒ Object
- #store_changes ⇒ Object
- #was_changed? ⇒ Boolean
- #was_saved ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 7 |
# File 'lib/multiplay/was_changed.rb', line 4 def self.included(base) base.send(:before_save, :store_changes) base.attribute_method_suffix '_was_changed?', '_before_save_was', '_before_save_change' end |
Instance Method Details
#attribute_before_save_change(attr) ⇒ Object
33 34 35 |
# File 'lib/multiplay/was_changed.rb', line 33 def attribute_before_save_change attr [@was_changed_attributes[attr], __send__(attr)] if attribute_was_changed?(attr) end |
#attribute_before_save_was(attr) ⇒ Object
29 30 31 |
# File 'lib/multiplay/was_changed.rb', line 29 def attribute_before_save_was attr attribute_was_changed?(attr) ? @was_changed_attributes[attr] : __send__(attr) end |
#attribute_was_changed?(attr) ⇒ Boolean
25 26 27 |
# File 'lib/multiplay/was_changed.rb', line 25 def attribute_was_changed? attr @was_changed_attributes.keys.include? attr end |
#saved_changes ⇒ Object
21 22 23 |
# File 'lib/multiplay/was_changed.rb', line 21 def saved_changes was_saved.inject({}) { |h, attr| h[attr] = attribute_before_save_change(attr); h } end |
#store_changes ⇒ Object
9 10 11 |
# File 'lib/multiplay/was_changed.rb', line 9 def store_changes @was_changed_attributes = @changed_attributes.clone end |
#was_changed? ⇒ Boolean
13 14 15 |
# File 'lib/multiplay/was_changed.rb', line 13 def was_changed? !@was_changed_attributes.empty? end |
#was_saved ⇒ Object
17 18 19 |
# File 'lib/multiplay/was_changed.rb', line 17 def was_saved @was_changed_attributes.keys end |