Module: ArchivedAttributes::SingletonMethods

Defined in:
lib/archived_attributes.rb

Instance Method Summary collapse

Instance Method Details

#archived_attribute(*args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/archived_attributes.rb', line 14

def archived_attribute(*args)
  attribute = args.first

  options = args.extract_options!
  options.reverse_merge! :marshalled => false

  if archived_attribute_definitions.nil?
    write_inheritable_attribute(:archived_attribute_definitions, {})

    before_save :generate_uuid
    before_save :save_archived_attributes
    before_destroy :destroy_archived_attributes
  end
  
  archived_attribute_definitions[attribute] = options

  self.__send__(:include, InstanceMethods)

  define_method attribute do
    archive_stash_for(attribute).value
  end

  define_method "#{attribute}=" do |value|
    archive_stash_for(attribute).value = value
  end
end

#archived_attribute_definitionsObject

Returns the attachment definitions defined by each call to has_attached_file.



43
44
45
# File 'lib/archived_attributes.rb', line 43

def archived_attribute_definitions
  read_inheritable_attribute(:archived_attribute_definitions)
end