state_machine
https://github.com/pluginaweek/state_machine
Ruby
Adds support for creating state machines for attributes on any Ruby class
StateMachine::Callback.bind_to_object
Determines whether to automatically bind the callback to the object
being transitioned. This only applies to callbacks that are defined as
lambda blocks (or Procs). Some integrations, such as DataMapper, handle
callbacks by executing them bound to the object involved, while other
integrations, such as ActiveRecord, pass the object as an argument to
the callback. This can be configured on an application-wide basis by
setting this configuration to +true+ or +false+. The default value
is +false+.
*Note* that the DataMapper and Sequel integrations automatically
configure this value on a per-callback basis, so it does not have to
be enabled application-wide.
== Examples
When not bound to the object:
class Vehicle
state_machine do
before_transition do |vehicle|
vehicle.set_alarm
end
end
def set_alarm
...
end
end
When bound to the object:
StateMachine::Callback.bind_to_object = true
class Vehicle
state_machine do
before_transition do
self.set_alarm
end
end
def set_alarm
...
end
endEdit
git clone [email protected]:pluginaweek/state_machine.git
cd state_machine
open lib/state_machine/callback.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-StateMachine--Callback-bind_to_object-for-pr
# Commit to gitgit add lib/state_machine/callback.rbgit commit -m "better docs for StateMachine::Callback.bind_to_object"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-StateMachine--Callback-bind_to_object-for-pr
hub pull-request
# Celebrate!