From d741086b200b304c17b0d060e43bb7b2052b98e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20B=C3=B6ttger?= Date: Sat, 17 Oct 2015 12:17:57 +1300 Subject: [PATCH] add support for global transition callbacks --- CHANGELOG.md | 4 ++++ PLANNED_CHANGES.md | 19 ------------------- README.md | 12 ++++++++++-- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78305da..65c3f22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 4.4.0 (not yet released) + + * add support global transation callbacks (see [issue #221](https://github.com/aasm/aasm/issues/221) and [issue #253](https://github.com/aasm/aasm/issues/253) for details) + ## 4.3.0 * add support for multiple state machines per class (see [issue #158](https://github.com/aasm/aasm/issues/158) and [issue #240](https://github.com/aasm/aasm/issues/240) for details) diff --git a/PLANNED_CHANGES.md b/PLANNED_CHANGES.md index 4dd23ea..987885c 100644 --- a/PLANNED_CHANGES.md +++ b/PLANNED_CHANGES.md @@ -7,24 +7,5 @@ # Currently working on - * support for global callbacks (see #221 and #253) - # Changes so far - -## version 4.3 - - * add support for multiple state machines per class - * class- and instance-level `aasm` methods accept a state machine selector - (aka the state machine _name_) - * if no selector/name is provided, `:default` will be used - * duplicate definitions of states and events will issue warnings - * check all tests - * _ActiveRecord_ - * _Mongoid_ - * _MongoMapper_ - * _Sequel_ - * what happen's if someone accesses `aasm`, but has defined a - state machine for `aasm(:my_name)`? - * documentation - * drop support for find_in_state, count_in_state, calculate_in_state, with_state_scope diff --git a/README.md b/README.md index b91827b..732129e 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,8 @@ class Job state :sleeping, :initial => true, :before_enter => :do_something state :running + after_all_transitions :log_status_change + event :run, :after => :notify_somebody do before do log('Preparing to run') @@ -117,6 +119,10 @@ class Job end end + def log_status_change + puts "changing from #{aasm.from_state} to #{aasm.to_state} (event: #{aasm.current_event})" + end + def set_process(name) ... end @@ -145,6 +151,7 @@ begin transition guards old_state before_exit old_state exit + after_all_transitions transition after new_state before_enter new_state enter @@ -172,8 +179,9 @@ Note that when passing arguments to a state transition, the first argument must In case of an error during the event processing the error is rescued and passed to `:error` callback, which can handle it or re-raise it for further propagation. -During the transition's `:after` callback (and reliably only then) you can access the -originating state (the from-state) and the target state (the to state), like this: +During the transition's `:after` callback (and reliably only then, or in the global +`after_all_transitions` callback) you can access the originating state (the from-state) +and the target state (the to state), like this: ```ruby def set_process(name)