1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

add support for global transition callbacks

This commit is contained in:
Thorsten Böttger 2015-10-17 12:17:57 +13:00
parent 6396847041
commit d741086b20
3 changed files with 14 additions and 21 deletions

View file

@ -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)

View file

@ -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

View file

@ -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)