Class: Roby::StateMachineDefinitionContext
- Defined in:
- lib/roby/coordination/task_state_machine.rb
Overview
Helper to get a more roby-like feeling to the state machine definitions
Instance Attribute Summary collapse
-
#state_machine ⇒ Object
readonly
Returns the value of attribute state_machine.
-
#task_model ⇒ Object
readonly
Returns the value of attribute task_model.
Instance Method Summary collapse
-
#initialize(task_model, state_machine) ⇒ StateMachineDefinitionContext
constructor
A new instance of StateMachineDefinitionContext.
- #method_missing(m, *args, &block) ⇒ Object
- #on(event, &block) ⇒ Object
- #poll_in_state(state, &block) ⇒ Object
- #respond_to_missing?(m, include_private) ⇒ Boolean
- #script_in_state(state, &block) ⇒ Object
Constructor Details
#initialize(task_model, state_machine) ⇒ StateMachineDefinitionContext
Returns a new instance of StateMachineDefinitionContext.
9 10 11 12 |
# File 'lib/roby/coordination/task_state_machine.rb', line 9 def initialize(task_model, state_machine) @task_model = task_model @state_machine = state_machine end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
45 46 47 |
# File 'lib/roby/coordination/task_state_machine.rb', line 45 def method_missing(m, *args, &block) state_machine.public_send(m, *args, &block) end |
Instance Attribute Details
#state_machine ⇒ Object (readonly)
Returns the value of attribute state_machine.
7 8 9 |
# File 'lib/roby/coordination/task_state_machine.rb', line 7 def state_machine @state_machine end |
#task_model ⇒ Object (readonly)
Returns the value of attribute task_model.
6 7 8 |
# File 'lib/roby/coordination/task_state_machine.rb', line 6 def task_model @task_model end |
Instance Method Details
#on(event, &block) ⇒ Object
37 38 39 |
# File 'lib/roby/coordination/task_state_machine.rb', line 37 def on(event, &block) state_machine.event(event, &block) end |
#poll_in_state(state, &block) ⇒ Object
31 32 33 34 35 |
# File 'lib/roby/coordination/task_state_machine.rb', line 31 def poll_in_state(state, &block) state_machine.state(state) do define_method(:poll, &block) end end |
#respond_to_missing?(m, include_private) ⇒ Boolean
41 42 43 |
# File 'lib/roby/coordination/task_state_machine.rb', line 41 def respond_to_missing?(m, include_private) state_machine.respond_to?(m) end |
#script_in_state(state, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/roby/coordination/task_state_machine.rb', line 14 def script_in_state(state, &block) script_engine = task_model.create_script(&block) state_machine.before_transition state_machine.any => state, do: lambda { |proxy| proxy.instance_variable_set :@script_engine, nil } state_machine.state(state) do define_method(:poll) do |task| if !@script_engine @script_engine = script_engine.bind(task) @script_engine.prepare @script_engine.step end end end end |