16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/aasm/bang.rb', line 16
def define_aasm_bang_method(name)
define_method("#{name}!") do |*args|
options = args[-1].is_a?(Hash) ? args.pop : {}
if options[:lifecycle] == false
if send(name)
self.class.where(:id => self.id).update_all(:updated_at => Time.now, :aasm_state => self.aasm_current_state)
else
raise(AASM::TransitionFailure, "cannot transition from '#{self.aasm_current_state}' to '#{name}'")
end
else
old_state = self.aasm_current_state
aasm_fire_event(name, true, *args) || begin
if errors.any?
raise(AASM::TransitionFailure, "record is invalid: #{errors.to_a.inspect}")
else
raise(AASM::TransitionFailure, "cannot transition from '#{old_state}' to '#{name}'")
end
end
end
end
end
|