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.
10 11 12 13 |
# File 'lib/roby/coordination/task_state_machine.rb', line 10 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
46 47 48 |
# File 'lib/roby/coordination/task_state_machine.rb', line 46 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.
8 9 10 |
# File 'lib/roby/coordination/task_state_machine.rb', line 8 def state_machine @state_machine end |
#task_model ⇒ Object (readonly)
Returns the value of attribute task_model.
8 9 10 |
# File 'lib/roby/coordination/task_state_machine.rb', line 8 def task_model @task_model end |
Instance Method Details
#on(event, &block) ⇒ Object
38 39 40 |
# File 'lib/roby/coordination/task_state_machine.rb', line 38 def on(event, &block) state_machine.event(event, &block) end |
#poll_in_state(state, &block) ⇒ Object
32 33 34 35 36 |
# File 'lib/roby/coordination/task_state_machine.rb', line 32 def poll_in_state(state, &block) state_machine.state(state) do define_method(:poll, &block) end end |
#respond_to_missing?(m, include_private) ⇒ Boolean
42 43 44 |
# File 'lib/roby/coordination/task_state_machine.rb', line 42 def respond_to_missing?(m, include_private) state_machine.respond_to?(m) end |
#script_in_state(state, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/roby/coordination/task_state_machine.rb', line 15 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| unless @script_engine @script_engine = script_engine.bind(task) @script_engine.prepare @script_engine.step end end end end |