Module: Roby::Models::TaskEvent

Includes:
MetaRuby::ModelAsClass
Included in:
TaskEvent
Defined in:
lib/roby/models/task_event.rb

Overview

Model-level API for task events

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#symbolSymbol

Returns the event name.

Returns:

  • (Symbol)

    the event name



20
21
22
# File 'lib/roby/models/task_event.rb', line 20

def symbol
  @symbol
end

#task_modelModel<Task>

The task model this event is defined on

Returns:



9
10
11
# File 'lib/roby/models/task_event.rb', line 9

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

Returns:

  • (Boolean)


14
# File 'lib/roby/models/task_event.rb', line 14

def controlable?; respond_to?(:call) end

#generalized_matchTaskEventGeneratorMatcher

Returns an object that allows to match all generators of this type, as well as any generator that is forwarded to it

Returns:

  • (TaskEventGeneratorMatcher)

    returns an object that allows to match all generators of this type, as well as any generator that is forwarded to it



56
57
58
# File 'lib/roby/models/task_event.rb', line 56

def generalized_match
    Queries::TaskEventGeneratorMatcher.new(task_model.match, symbol.to_s).generalized
end

#matchTaskEventGeneratorMatcher

Returns an object that allows to match all generators of this type

Returns:

  • (TaskEventGeneratorMatcher)

    returns an object that allows to match all generators of this type



49
50
51
# File 'lib/roby/models/task_event.rb', line 49

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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/roby/models/task_event.rb', line 22

def setup_submodel(submodel, task_model: nil, symbol: nil, command: false, terminal: false, **options, &block)
    super(submodel, options, &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