lib/transitions/machine.rb in transitions-0.1.13 vs lib/transitions/machine.rb in transitions-0.2.0

- old
+ new

@@ -15,28 +15,31 @@ def update(options = {}, &block) @initial_state = options[:initial] if options.key?(:initial) @auto_scopes = options[:auto_scopes] instance_eval(&block) if block - include_scopes if @auto_scopes && ::Transitions.active_record_descendant?(klass) + include_scopes if @auto_scopes && ::Transitions.active_model_descendant?(klass) self end # TODO There is still way to much parameter passing around going on down below. def fire_event(event, record, persist, *args) handle_state_exit_callback record if new_state = transition_to_new_state(record, event, *args) handle_state_enter_callback record, new_state - handle_event_fired_calllback record, new_state, event + handle_event_fired_callback record, new_state, event record.update_current_state(new_state, persist) handle_event_success_callback record, event + return true else handle_event_failed_callback record, event + return false end rescue => e if record.respond_to?(:event_failed) record.send(:event_failed, event) + return false else raise e end end @@ -62,10 +65,10 @@ def handle_state_enter_callback(record, new_state) state_index[new_state].call_action(:enter, record) end - def handle_event_fired_calllback(record, new_state, event) + def handle_event_fired_callback(record, new_state, event) if record.respond_to?(:event_fired, true) record.send(:event_fired, record.current_state, new_state, event) end end