Class: Roby::Actions::Action

Inherits:
Object
  • Object
show all
Includes:
DRoby::V5::Actions::ActionDumper
Defined in:
lib/roby/actions/action.rb,
lib/roby/droby/enable.rb

Overview

The representation of an action, as a model and arguments

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DRoby::V5::Actions::ActionDumper

#droby_dump, #droby_dump!, #proxy, #proxy!

Constructor Details

#initialize(model, **arguments) ⇒ Action

Returns a new instance of Action.



12
13
14
# File 'lib/roby/actions/action.rb', line 12

def initialize(model, **arguments)
    @model, @arguments = model, arguments
end

Instance Attribute Details

#argumentsHash (readonly)

The action arguments

Returns:

  • (Hash)


10
11
12
# File 'lib/roby/actions/action.rb', line 10

def arguments
  @arguments
end

#modelModels::Action

The action model

Returns:



7
8
9
# File 'lib/roby/actions/action.rb', line 7

def model
  @model
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
23
24
# File 'lib/roby/actions/action.rb', line 20

def ==(other)
    other.kind_of?(Action) &&
        model == other.model &&
        arguments == other.arguments
end

#as_plan(**arguments) ⇒ Roby::Task

Returns a plan pattern that would deploy this action in the plan

Returns:



54
55
56
# File 'lib/roby/actions/action.rb', line 54

def as_plan(**arguments)
    model.plan_pattern(**self.arguments.merge(arguments))
end

#has_missing_required_arg?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
# File 'lib/roby/actions/action.rb', line 35

def has_missing_required_arg?
    model.arguments.any? do |arg|
        arg_sym = arg.name.to_sym
        if arguments.has_key?(arg_sym)
            TaskArguments.delayed_argument?(arguments.fetch(arg_sym))
        else
            arg.required?
        end
    end
end

#instanciate(plan, **arguments) ⇒ Object

Deploys this action on the given plan



63
64
65
# File 'lib/roby/actions/action.rb', line 63

def instanciate(plan, **arguments)
    model.instanciate(plan, self.arguments.merge(arguments))
end

#nameObject



16
17
18
# File 'lib/roby/actions/action.rb', line 16

def name
    model.name
end

#rebind(action_interface_model) ⇒ Object



58
59
60
# File 'lib/roby/actions/action.rb', line 58

def rebind(action_interface_model)
    model.rebind(action_interface_model).new(**arguments)
end

#returned_typeObject

The task model returned by this action



47
48
49
# File 'lib/roby/actions/action.rb', line 47

def returned_type
    model.returned_type
end

#to_actionObject



75
76
77
# File 'lib/roby/actions/action.rb', line 75

def to_action
    self
end

#to_coordination_task(task_model = Roby::Task) ⇒ Object



71
72
73
# File 'lib/roby/actions/action.rb', line 71

def to_coordination_task(task_model = Roby::Task)
    Coordination::Models::TaskFromAction.new(self)
end

#to_sObject



67
68
69
# File 'lib/roby/actions/action.rb', line 67

def to_s
    "#{model}(#{arguments.map { |k,v| "#{k} => #{v}" }.sort.join(", ")})"
end

#with_arguments(**arguments) ⇒ self

Update this object with new arguments and returns it

Parameters:

  • arguments (Hash)

    new arguments

Returns:

  • (self)


30
31
32
33
# File 'lib/roby/actions/action.rb', line 30

def with_arguments(**arguments)
    @arguments.merge!(arguments)
    self
end