15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/memento/active_record_methods.rb', line 15
def memento_changes(*action_types)
if defined?(@memento_initialized) && @memento_initialized
raise "Memento initialized twice. Use memento_changes only once per model"
end
@memento_initialized = true
include InstanceMethods
self.memento_options = action_types.last.is_a?(Hash) ? action_types.pop : {}
action_types = Memento::Action::Base.action_types if action_types.empty?
action_types.map!(&:to_s).uniq!
unless (invalid = action_types - Memento::Action::Base.action_types).empty?
raise ArgumentError.new("Invalid memento_changes: #{invalid.to_sentence}; allowed are only #{Memento::Action::Base.action_types.to_sentence}")
end
action_types.each do |action_type|
send :"after_#{action_type}", :"record_#{action_type}"
end
has_many :memento_states, :class_name => "Memento::State", :as => :record
end
|