Class: ResourceSubscriber::Changes

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/resource_subscriber/changes.rb

Instance Method Summary collapse

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

Returns:

  • (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