lib/aasm.rb in runcoderun-aasm-2.0.2.1 vs lib/aasm.rb in runcoderun-aasm-2.0.2.2

- old
+ new

@@ -2,32 +2,29 @@ require File.join(File.dirname(__FILE__), 'state') require File.join(File.dirname(__FILE__), 'state_machine') require File.join(File.dirname(__FILE__), 'persistence') module AASM - def self.Version - '2.0.2.1' - end - class InvalidTransition < RuntimeError end def self.included(base) #:nodoc: # TODO - need to ensure that a machine is being created because # AASM was either included or arrived at via inheritance. It # cannot be both. base.extend AASM::ClassMethods AASM::Persistence.set_persistence(base) AASM::StateMachine[base] = AASM::StateMachine.new('') - end - module ClassMethods - def inherited(klass) - AASM::StateMachine[klass] = AASM::StateMachine[self].dup - super + base.class_eval do + def base.inherited(klass) + AASM::StateMachine[klass] = AASM::StateMachine[self].dup + end end + end + module ClassMethods def aasm_initial_state(set_state=nil) if set_state AASM::StateMachine[self].initial_state = set_state else AASM::StateMachine[self].initial_state @@ -97,18 +94,15 @@ events = self.class.aasm_events.values.select {|event| event.transitions_from_state?(state) } events.map {|event| event.name} end private - def set_aasm_current_state_with_persistence(state) - save_success = true + def aasm_current_state_with_persistence=(state) if self.respond_to?(:aasm_write_state) || self.private_methods.include?('aasm_write_state') - save_success = aasm_write_state(state) + aasm_write_state(state) end - self.aasm_current_state = state if save_success - - save_success + self.aasm_current_state = state end def aasm_current_state=(state) if self.respond_to?(:aasm_write_state_without_persistence) || self.private_methods.include?('aasm_write_state_without_persistence') aasm_write_state_without_persistence(state) @@ -124,27 +118,24 @@ aasm_state_object_for_state(aasm_current_state).call_action(:exit, self) new_state = self.class.aasm_events[name].fire(self, *args) unless new_state.nil? - aasm_state_object_for_state(new_state).call_action(:enter, self) - - persist_successful = true if persist - persist_successful = set_aasm_current_state_with_persistence(new_state) - self.class.aasm_events[name].execute_success_callback(self) if persist_successful + self.aasm_current_state_with_persistence = new_state else self.aasm_current_state = new_state - self.class.aasm_events[name].execute_success_callback(self) end - - if persist_successful - self.aasm_event_fired(self.aasm_current_state, new_state) if self.respond_to?(:aasm_event_fired) - else - self.aasm_event_failed(name) if self.respond_to?(:aasm_event_failed) + + self.send(self.class.aasm_events[name].success) if self.class.aasm_events[name].success + + aasm_state_object_for_state(new_state).call_action(:enter, self) + + if self.respond_to?(:aasm_event_fired) + self.aasm_event_fired(self.aasm_current_state, new_state) end - persist_successful + true else if self.respond_to?(:aasm_event_failed) self.aasm_event_failed(name) end