Class: Roby::Actions::Models::MethodAction
- Defined in:
- lib/roby/actions/models/method_action.rb,
lib/roby/droby/enable.rb
Overview
Action defined by a method on an Interface
Instance Attribute Summary collapse
-
#action_interface_model ⇒ Object
The action interface on which this action is defined.
Attributes inherited from Action
#arguments, #doc, #name, #returned_type
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(action_interface_model, doc = nil) ⇒ MethodAction
constructor
A new instance of MethodAction.
-
#instanciate(plan, arguments = Hash.new) ⇒ Object
Instanciate this action on the given plan.
-
#plan_pattern(arguments = Hash.new) ⇒ Object
Returns the plan pattern that will deploy this action on the plan.
-
#rebind(action_interface_model) ⇒ Action
Create a new action model that is bound to a different interface model.
- #to_s ⇒ Object
Methods included from DRoby::V5::Actions::Models::MethodActionDumper
Methods included from DRoby::V5::Actions::Models::InterfaceActionDumper
#droby_dump!, #proxy_from_existing
Methods inherited from Action
#advanced, #as_plan, #each_arg, #find_arg, #has_arg?, #has_required_arg?, #initialize_copy, #new, #normalize_arguments, #optional_arg, #overloads, #pretty_print, #required_arg, #returned_task_type, #returns, #to_action, #to_action_model, #validate_can_overload
Methods included from DRoby::V5::Actions::Models::ActionDumper
#droby_dump, #droby_dump!, #proxy, #proxy!
Constructor Details
#initialize(action_interface_model, doc = nil) ⇒ MethodAction
Returns a new instance of MethodAction.
9 10 11 12 |
# 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 |
Instance Attribute Details
#action_interface_model ⇒ Object
The action interface on which this action is defined
7 8 9 |
# File 'lib/roby/actions/models/method_action.rb', line 7 def action_interface_model @action_interface_model end |
Instance Method Details
#==(other) ⇒ Object
18 19 20 21 22 |
# 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) ⇒ Object
Instanciate this action on the given plan
25 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 53 54 55 56 |
# 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. 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) ⇒ Object
Returns the plan pattern that will deploy this action on the plan
74 75 76 77 78 79 80 81 |
# File 'lib/roby/actions/models/method_action.rb', line 74 def plan_pattern(arguments = Hash.new) job_id, arguments = Kernel. 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) ⇒ Action
Create a new action model that is bound to a different interface model
65 66 67 68 69 70 71 |
# 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 ⇒ Object
14 15 16 |
# File 'lib/roby/actions/models/method_action.rb', line 14 def to_s "#{super} of #{action_interface_model}" end |