Module: ArchivedAttributes::InstanceMethods

Defined in:
lib/archived_attributes.rb

Instance Method Summary collapse

Instance Method Details

#archive_stash_for(model) ⇒ Object



50
51
52
53
54
55
# File 'lib/archived_attributes.rb', line 50

def archive_stash_for(model)
  @_archived_attribute_stashes ||= {}
  @_archived_attribute_stashes[model] ||= ArchivedAttribute.new(
    model, self, self.class.archived_attribute_definitions[model]
  )
end

#destroy_archived_attributesObject



69
70
71
72
73
# File 'lib/archived_attributes.rb', line 69

def destroy_archived_attributes
  each_archived_stash do |name, stash|
    stash.__send__(:destroy)
  end
end

#each_archived_stashObject



57
58
59
60
61
# File 'lib/archived_attributes.rb', line 57

def each_archived_stash
  self.class.archived_attribute_definitions.each do |name, definition|
    yield(name, archive_stash_for(name))
  end
end

#generate_uuidObject



75
76
77
# File 'lib/archived_attributes.rb', line 75

def generate_uuid
  self.uuid = UUID.new.generate if self.new_record?
end

#save_archived_attributesObject



63
64
65
66
67
# File 'lib/archived_attributes.rb', line 63

def save_archived_attributes
  each_archived_stash do |name, stash|
    stash.__send__(:save)
  end
end