Module: Roby::Models::TaskEvent
Overview
Model-level API for task events
Instance Attribute Summary collapse
-
#symbol ⇒ Symbol
The event name.
-
#task_model ⇒ Model<Task>
The task model this event is defined on.
Instance Method Summary collapse
-
#controlable? ⇒ Boolean
If the event model defines a controlable event By default, an event is controlable if the model responds to #call.
-
#generalized_match ⇒ TaskEventGeneratorMatcher
Returns an object that allows to match all generators of this type, as well as any generator that is forwarded to it.
-
#match ⇒ TaskEventGeneratorMatcher
Returns an object that allows to match all generators of this type.
- #setup_submodel(submodel, task_model: nil, symbol: nil, command: false, terminal: false, **options, &block) ⇒ Object
Instance Attribute Details
#symbol ⇒ Symbol
Returns the event name.
24 25 26 |
# File 'lib/roby/models/task_event.rb', line 24 def symbol @symbol end |
#task_model ⇒ Model<Task>
The task model this event is defined on
11 12 13 |
# File 'lib/roby/models/task_event.rb', line 11 def task_model @task_model end |
Instance Method Details
#controlable? ⇒ Boolean
If the event model defines a controlable event By default, an event is controlable if the model responds to #call
16 17 18 |
# File 'lib/roby/models/task_event.rb', line 16 def controlable? respond_to?(:call) end |
#generalized_match ⇒ TaskEventGeneratorMatcher
Returns an object that allows to match all generators of this type, as well as any generator that is forwarded to it
63 64 65 66 67 |
# File 'lib/roby/models/task_event.rb', line 63 def generalized_match Queries::TaskEventGeneratorMatcher .new(task_model.match, symbol.to_s) .generalized end |
#match ⇒ TaskEventGeneratorMatcher
Returns an object that allows to match all generators of this type
56 57 58 |
# File 'lib/roby/models/task_event.rb', line 56 def match Queries::TaskEventGeneratorMatcher.new(task_model.match, symbol.to_s) end |
#setup_submodel(submodel, task_model: nil, symbol: nil, command: false, terminal: false, **options, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/roby/models/task_event.rb', line 26 def setup_submodel( submodel, task_model: nil, symbol: nil, command: false, terminal: false, **, &block ) super(submodel, **, &block) submodel.task_model = task_model submodel.symbol = symbol submodel.terminal = terminal if command if command.respond_to?(:call) # check that the supplied command handler can take two arguments check_arity(command, 2, strict: true) submodel.singleton_class.class_eval do define_method(:call, &command) end else submodel.singleton_class.class_eval do def call(task, context) # :nodoc: task.event(symbol).emit(*context) end end end end submodel end |