Module: HashPipe::InstanceMethods

Defined in:
lib/hashpipe.rb

Instance Method Summary collapse

Instance Method Details

#archive_stash_for(attribute) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/hashpipe.rb', line 60

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

#archived_attribute_scopeObject



70
71
72
# File 'lib/hashpipe.rb', line 70

def archived_attribute_scope
  "#{self.class.table_name}_#{id}"
end

#destroy_archived_attributesObject



87
88
89
90
91
# File 'lib/hashpipe.rb', line 87

def destroy_archived_attributes
  each_archived_stash do |name, stash|
    stash.destroy
  end
end

#each_archived_stashObject



74
75
76
77
78
# File 'lib/hashpipe.rb', line 74

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

#save_archived_attributesObject



80
81
82
83
84
85
# File 'lib/hashpipe.rb', line 80

def save_archived_attributes
  each_archived_stash do |name, stash|
    stash.scope = archived_attribute_scope
    stash.save
  end
end