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.



14
15
16
# File 'lib/roby/actions/action.rb', line 14

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

Instance Attribute Details

#argumentsHash (readonly)

The action arguments

Returns:

  • (Hash)


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

def arguments
  @arguments
end

#modelModels::Action

The action model

Returns:



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

def model
  @model
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
25
26
# File 'lib/roby/actions/action.rb', line 22

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:



78
79
80
# File 'lib/roby/actions/action.rb', line 78

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

#has_missing_required_arg?Boolean

Check whether the action model has required arguments missing

Returns:

  • (Boolean)


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

def has_missing_required_arg?
    !missing_required_arguments.empty?
end

#instanciate(plan, **arguments) ⇒ Object

Deploys this action on the given plan



87
88
89
# File 'lib/roby/actions/action.rb', line 87

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

#missing_required_argumentsArray<Models::Action::Argument>

List of required arguments that are currently not set

Returns:



40
41
42
43
44
45
46
47
48
49
# File 'lib/roby/actions/action.rb', line 40

def missing_required_arguments
    model.arguments.find_all 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

#nameObject



18
19
20
# File 'lib/roby/actions/action.rb', line 18

def name
    model.name
end

#rebind(action_interface_model) ⇒ Object



82
83
84
# File 'lib/roby/actions/action.rb', line 82

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

#returned_typeObject

The task model returned by this action



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

def returned_type
    model.returned_type
end

#to_actionObject



99
100
101
# File 'lib/roby/actions/action.rb', line 99

def to_action
    self
end

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



95
96
97
# File 'lib/roby/actions/action.rb', line 95

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

#to_sObject



91
92
93
# File 'lib/roby/actions/action.rb', line 91

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)


32
33
34
35
# File 'lib/roby/actions/action.rb', line 32

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

#with_example_argumentsObject

Fill missing required arguments with example arguments when available



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/roby/actions/action.rb', line 52

def with_example_arguments
    new_args = missing_required_arguments.each_with_object({}) do |arg, h|
        # If an argument has a default value but it received a delayed
        # argument, then use the default value as its example
        if !arg.required?
            h[arg.name.to_sym] = arg.default
        elsif arg.example_defined?
            h[arg.name.to_sym] = arg.example
        end
    end
    with_arguments(**new_args)
end