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



24
25
26
# File 'lib/roby/models/task_event.rb', line 24

def symbol
  @symbol
end

#task_modelModel<Task>

The task model this event is defined on

Returns:



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

Returns:

  • (Boolean)


16
17
18
# File 'lib/roby/models/task_event.rb', line 16

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



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

#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



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, **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