Class: Recorder::Revision
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Recorder::Revision
- Defined in:
- lib/recorder/revision.rb
Instance Method Summary collapse
-
#association_changeset(name) ⇒ Recorder::Changeset
Get changeset for an association.
-
#changed_associations ⇒ Array
Get names of item associations that has been changed.
- #item ⇒ Object
-
#item_changeset ⇒ Recorder::Changeset
Get changeset for an item.
Instance Method Details
#association_changeset(name) ⇒ Recorder::Changeset
Get changeset for an association
64 65 66 67 68 69 |
# File 'lib/recorder/revision.rb', line 64 def association_changeset(name) association = item.send(name) # association = association.source if association.decorated? changeset_class(association).new(association, data['associations'].fetch(name.to_s).try(:fetch, 'changes')) end |
#changed_associations ⇒ Array
Get names of item associations that has been changed
57 58 59 |
# File 'lib/recorder/revision.rb', line 57 def changed_associations data['associations'].try(:keys) || [] end |
#item ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/recorder/revision.rb', line 30 def item return @item if defined?(@item) return if item_id.nil? @item = item_type.classify.constantize.new(data['attributes']) if data['associations'].present? data['associations'].each do |name, association| @item.send("build_#{name}", association['attributes']) end end @item end |
#item_changeset ⇒ Recorder::Changeset
Get changeset for an item
47 48 49 50 51 52 53 |
# File 'lib/recorder/revision.rb', line 47 def item_changeset return @item_changeset if defined?(@item_changeset) return nil if item.nil? return nil if data['changes'].nil? @item_changeset ||= changeset_class(item).new(item, data['changes']) end |