module Roby::Models::TaskEvent

Model-level API for task events

Attributes

symbol[RW]

@return [Symbol] the event name

task_model[RW]

The task model this event is defined on @return [Model<Task>]

Public Instance Methods

controlable?() click to toggle source

If the event model defines a controlable event By default, an event is controlable if the model responds to call

# File lib/roby/models/task_event.rb, line 14
def controlable?; respond_to?(:call) end
generalized_match() click to toggle source

@return [TaskEventGeneratorMatcher] returns an object that allows

to match all generators of this type, as well as any generator
that is forwarded to it
# File lib/roby/models/task_event.rb, line 56
def generalized_match
    Queries::TaskEventGeneratorMatcher.new(task_model.match, symbol.to_s).generalized
end
match() click to toggle source

@return [TaskEventGeneratorMatcher] returns an object that allows

to match all generators of this type
# 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) click to toggle source
Calls superclass method
# 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