Class: Recorder::Changeset
- Inherits:
-
Object
- Object
- Recorder::Changeset
- Defined in:
- lib/recorder/changeset.rb
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#item ⇒ Object
readonly
Returns the value of attribute item.
Instance Method Summary collapse
- #human_attribute_name(attribute) ⇒ Object
-
#initialize(item, changes) ⇒ Changeset
constructor
A new instance of Changeset.
- #keys ⇒ Object
- #next(attribute) ⇒ Object
- #next_version ⇒ Object
- #previous(attribute) ⇒ Object
- #previous_version ⇒ Object
Constructor Details
#initialize(item, changes) ⇒ Changeset
Returns a new instance of Changeset.
5 6 7 |
# File 'lib/recorder/changeset.rb', line 5 def initialize(item, changes) @item = item; @changes = changes end |
Instance Attribute Details
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
3 4 5 |
# File 'lib/recorder/changeset.rb', line 3 def changes @changes end |
#item ⇒ Object (readonly)
Returns the value of attribute item.
3 4 5 |
# File 'lib/recorder/changeset.rb', line 3 def item @item end |
Instance Method Details
#human_attribute_name(attribute) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/recorder/changeset.rb', line 13 def human_attribute_name(attribute) if defined?(Draper) && self.item.decorated? self.item.source.class.human_attribute_name(attribute.to_s) else self.item.class.human_attribute_name(attribute.to_s) end end |
#keys ⇒ Object
9 10 11 |
# File 'lib/recorder/changeset.rb', line 9 def keys self.changes.keys end |
#next(attribute) ⇒ Object
40 41 42 43 |
# File 'lib/recorder/changeset.rb', line 40 def next(attribute) self.try("next_#{attribute}") || self.next_version.send(attribute) # self.next_version.try("display_#{attribute}") || self.next_version.try(attribute) end |
#next_version ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/recorder/changeset.rb', line 45 def next_version return @next_version if defined?(@next_version) @next_version = self.item.dup self.changes.each do |key, change| @next_version.send("#{key}=", change[1]) end @next_version end |
#previous(attribute) ⇒ Object
22 23 24 25 26 |
# File 'lib/recorder/changeset.rb', line 22 def previous(attribute) # self.changes[attribute.to_s][0] # self.previous_version.try("display_#{attribute}") || self.previous_version.try(attribute) self.try("previous_#{attribute}") || self.previous_version.try(attribute) end |
#previous_version ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/recorder/changeset.rb', line 28 def previous_version return @previous_version if defined?(@previous_version) @previous_version = self.item.dup self.changes.each do |key, change| @previous_version.send("#{key}=", change[0]) end @previous_version end |