Class: ResourceSubscriber::Changes
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ResourceSubscriber::Changes
- Defined in:
- lib/resource_subscriber/changes.rb
Instance Method Summary collapse
- #__getobj__ ⇒ Object
-
#initialize(changes) ⇒ Changes
constructor
A new instance of Changes.
- #was_changed?(attribute_name, to: nil, from: nil) ⇒ Boolean
Constructor Details
#initialize(changes) ⇒ Changes
Returns a new instance of Changes.
3 4 5 |
# File 'lib/resource_subscriber/changes.rb', line 3 def initialize(changes) @changes = changes.with_indifferent_access end |
Instance Method Details
#__getobj__ ⇒ Object
7 8 9 |
# File 'lib/resource_subscriber/changes.rb', line 7 def __getobj__ @changes end |
#was_changed?(attribute_name, to: nil, from: nil) ⇒ Boolean
11 12 13 14 15 16 17 18 19 |
# File 'lib/resource_subscriber/changes.rb', line 11 def was_changed?(attribute_name, to:nil, from:nil) result = true value = self[attribute_name] result &&= !!value result &&= self.key?(attribute_name) result &&= (to == self[attribute_name][1]) if to result &&= (from == self[attribute_name][0]) if from result end |