class Roby::Actions::Models::MethodAction

Action defined by a method on an {Interface}

Attributes

action_interface_model[RW]

The action interface on which this action is defined

Public Class Methods

new(action_interface_model, doc = nil) click to toggle source
Calls superclass method Roby::Actions::Models::Action#new
# File lib/roby/actions/models/method_action.rb, line 9
def initialize(action_interface_model, doc = nil)
    super(doc)
    @action_interface_model = action_interface_model
end

Public Instance Methods

==(other) click to toggle source
# File lib/roby/actions/models/method_action.rb, line 18
def ==(other)
    other.kind_of?(self.class) &&
        other.action_interface_model == action_interface_model &&
        other.name == name
end
instanciate(plan, arguments = Hash.new) click to toggle source

Instanciate this action on the given plan

# File lib/roby/actions/models/method_action.rb, line 25
def instanciate(plan, arguments = Hash.new)
    action_interface = action_interface_model.new(plan)

    if self.arguments.empty?
        if !arguments.empty?
            raise ArgumentError, "#{name} expects no arguments, but #{arguments.size} are given"
        end
        result = action_interface.send(name).as_plan
    else
        default_arguments = self.arguments.inject(Hash.new) do |h, arg|
            h[arg.name] = arg.default
            h
        end
        arguments = Kernel.validate_options arguments, default_arguments
        self.arguments.each do |arg|
            if arg.required && !arguments.has_key?(arg.name.to_sym)
                raise ArgumentError, "required argument #{arg.name} not given to #{name}"
            end
        end
        result = action_interface.send(name, arguments).as_plan
    end
    # Make the planning task inherit the model/argument flags
    if planning_task = result.planning_task
        if planning_task.respond_to?(:action_model=)
            planning_task.action_model ||= self
        end
        if planning_task.respond_to?(:action_arguments=)
            result.planning_task.action_arguments ||= arguments
        end
    end
    result
end
plan_pattern(arguments = Hash.new) click to toggle source

Returns the plan pattern that will deploy this action on the plan

# File lib/roby/actions/models/method_action.rb, line 74
def plan_pattern(arguments = Hash.new)
    job_id, arguments = Kernel.filter_options arguments, :job_id

    planner = Roby::Actions::Task.new(
        Hash[action_model: self,
             action_arguments: arguments].merge(job_id))
    planner.planning_result_task
end
rebind(action_interface_model) click to toggle source

Create a new action model that is bound to a different interface model

@param [Models::Interface] action_interface_model the new model @param [Boolean] force the rebind will happen only if the new

interface model is a submodel of the current one. If force is
true, it will be done regardless.

@return [Action] the rebound action model

# File lib/roby/actions/models/method_action.rb, line 65
def rebind(action_interface_model)
    rebound = dup
    if action_interface_model <= self.action_interface_model
        rebound.action_interface_model = action_interface_model
    end
    rebound
end
to_s() click to toggle source
# File lib/roby/actions/models/method_action.rb, line 14
def to_s
    "#{super} of #{action_interface_model}"
end