class Recorder::Revision
Public Instance Methods
association_changeset(name)
click to toggle source
Get changeset for an association @param name [String] name of association to return changeset @return [Recorder::Changeset]
# 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()
click to toggle source
Get names of item associations that has been changed @return [Array]
# File lib/recorder/revision.rb, line 57 def changed_associations data['associations'].try(:keys) || [] end
item()
click to toggle source
# 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()
click to toggle source
Get changeset for an item @return [Recorder::Changeset]
# 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
Protected Instance Methods
changeset_class(object)
click to toggle source
Returns changeset class for passed object. Changeset
class name can be overriden with `#recorder_changeset_class` method. If `#recorder_changeset_class` method is not defined, then class name is generated as “#{class}Changeset” @api private
# File lib/recorder/revision.rb, line 77 def changeset_class(object) klass = defined?(Draper) && object.decorated? ? object.source.class : object.class klass = klass.base_class return klass.send(:recorder_changeset_class) if klass.respond_to?(:recorder_changeset_class) klass = "#{klass}Changeset" klass = begin klass.constantize rescue nil end klass.present? ? klass : Recorder::Changeset end