Module: RecordHistory::Model::ClassMethods

Defined in:
lib/record_history/has_record_history.rb

Instance Method Summary collapse

Instance Method Details

#has_record_history(options = {}) ⇒ Object



10
11
12
13
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/record_history/has_record_history.rb', line 10

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

  attr_accessor :record_history_obj

  class_attribute :record_history_ignore
  self.record_history_ignore = ([options[:ignore]].flatten.compact || []).map{|attr| attr.to_s}

  class_attribute :record_history_only
  self.record_history_only = ([options[:only]].flatten.compact || []).map{|attr| attr.to_s}

  class_attribute :record_history_on
  self.record_history_on = ([options[:on] || ['create', 'update']].flatten.compact).map{|attr| attr.to_s}

  class_attribute :record_history_polymorphic_group
  self.record_history_polymorphic_group = ([options[:polymorphic_group]].flatten.compact || []).map{|attr| attr.to_s}

  has_many :record_history,
           :class_name => 'RecordHistoryModel',
           :order      => "created_at DESC",
           :as         => :item
  if self.record_history_on.include?('update')
    before_save  :build_history_on_update
    after_update :save_history_on_update
  end

  if self.record_history_on.include?('create')
    after_create :save_history_on_create
  end
end

#is_record_history_author(options = {}) ⇒ Object



41
42
43
44
45
46
# File 'lib/record_history/has_record_history.rb', line 41

def is_record_history_author(options={})
  has_many :written_history,
           :class_name => 'RecordHistoryModel',
           :order      => "created_at DESC",
           :as         => :author
end