Method: StateMachine::Callback.bind_to_object
- Defined in:
- lib/state_machine/callback.rb
.bind_to_object ⇒ 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
end
55 56 57 |
# File 'lib/state_machine/callback.rb', line 55 def bind_to_object @bind_to_object end |