Class: Recorder::Revision

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/recorder/revision.rb

Instance Method Summary collapse

Instance Method Details

#association_changeset(name) ⇒ Recorder::Changeset

Get changeset for an association

Parameters:

  • name (String)

    name of association to return changeset

Returns:



46
47
48
49
50
51
# File 'lib/recorder/revision.rb', line 46

def association_changeset(name)
  association = self.item.send(name)
  # association = association.source if association.decorated?

  self.changeset_class(association).new(association, self.data['associations'].fetch(name.to_s).try(:fetch, 'changes'))
end

#changed_associationsArray

Get names of item associations that has been changed

Returns:

  • (Array)


39
40
41
# File 'lib/recorder/revision.rb', line 39

def changed_associations
  self.data['associations'].try(:keys) || []
end

#item_changesetRecorder::Changeset

Get changeset for an item

Returns:



30
31
32
33
34
35
# File 'lib/recorder/revision.rb', line 30

def item_changeset
  return @item_changeset if defined?(@item_changeset)
  return nil if self.data['changes'].nil?

  @item_changeset ||= self.changeset_class(self.item).new(self.item, self.data['changes'])
end