Module: PaperTrail::ClassMethods

Defined in:
lib/paper_trail/has_paper_trail.rb

Instance Method Summary collapse

Instance Method Details

#has_paper_trail(options = {}) ⇒ Object

Options: :ignore an array of attributes for which a new Version will not be created if only they change. :meta a hash of extra data to store. You must add a column to the versions table for each key.

Values are objects or procs (which are called with +self+, i.e. the model with the paper
trail).


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/paper_trail/has_paper_trail.rb', line 14

def has_paper_trail(options = {})
  send :include, InstanceMethods

  cattr_accessor :ignore
  self.ignore = (options[:ignore] || []).map &:to_s

  cattr_accessor :meta
  self.meta = options[:meta] || {}
  
  cattr_accessor :paper_trail_active
  self.paper_trail_active = true

  has_many :versions, :as => :item, :order => 'created_at ASC, id ASC'

  after_create  :record_create
  before_update :record_update
  after_destroy :record_destroy
end

#paper_trail_offObject



33
34
35
# File 'lib/paper_trail/has_paper_trail.rb', line 33

def paper_trail_off
  self.paper_trail_active = false
end

#paper_trail_onObject



37
38
39
# File 'lib/paper_trail/has_paper_trail.rb', line 37

def paper_trail_on
  self.paper_trail_active = true
end