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
|