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 8 |
# File 'lib/recorder/changeset.rb', line 5 def initialize(item, changes) @item = item; @changes = Hash[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
14 15 16 17 18 19 20 |
# File 'lib/recorder/changeset.rb', line 14 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
10 11 12 |
# File 'lib/recorder/changeset.rb', line 10 def keys self.changes.try(:keys) || [] end |
#next(attribute) ⇒ Object
38 39 40 |
# File 'lib/recorder/changeset.rb', line 38 def next(attribute) self.try("next_#{attribute}") || self.next_version.send(attribute) end |
#next_version ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/recorder/changeset.rb', line 42 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 |
# File 'lib/recorder/changeset.rb', line 22 def previous(attribute) self.try("previous_#{attribute}") || self.previous_version.try(attribute) end |
#previous_version ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/recorder/changeset.rb', line 26 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 |