Module: Archivist::Base::ClassMethods

Defined in:
lib/archivist/base.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_archive(options = {}) ⇒ Object



64
65
66
# File 'lib/archivist/base.rb', line 64

def acts_as_archive(options={})
  has_archive(options)
end

#has_archive(options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/archivist/base.rb', line 17

def has_archive(options={})
  options = DEFAULT_OPTIONS.merge(options)
  options[:allow_multiple_archives] = true if options[:associate_with_original]
  
  class_eval <<-EOF
    alias_method :delete!, :delete
    
    class << self
      alias_method :delete_all!, :delete_all
    end
    
    def self.archive_indexes
      #{Array(options[:indexes]).collect{|i| i.to_s}.inspect}
    end

    def self.archive_options
      #{options.inspect}
    end
    
    def self.has_archive?
      true
    end
    
    def self.acts_as_archive?
      warn "DEPRECATION WARNING: #acts_as_archive is provided for compatibility with AAA and will be removed soon, please use has_archive?"
      has_archive?
    end

    class Archive < ActiveRecord::Base
      self.record_timestamps = false
      self.table_name = "archived_#{self.table_name}"
      #{build_serialization_strings(self.serialized_attributes)}
      #{build_belongs_to_association(options[:associate_with_original])}
      #{build_inclusion_strings(options[:included_modules])}
      include Archivist::ArchiveMethods
    end

    #{build_has_many_association(options[:associate_with_original])}
    
    #{build_copy_self_to_archive(options[:allow_multiple_archives])}
  EOF
  
  include InstanceMethods
  extend ClassExtensions
  include DB
end