Class: Roby::Coordination::Models::TaskFromVariable

Inherits:
TaskWithDependencies show all
Defined in:
lib/roby/coordination/models/task_from_variable.rb

Overview

State whose instanciation object is provided through a state machine variable

Instance Attribute Summary collapse

Attributes inherited from TaskWithDependencies

#dependencies

Attributes inherited from Task

#model, #name

Instance Method Summary collapse

Methods inherited from TaskWithDependencies

#depends_on, #find_child_model, #initialize_copy, #map_tasks

Methods inherited from Task

#can_resolve_child_models?, #find_child, #find_child_model, #find_event, #find_through_method_missing, #has_child?, #has_event?, #has_through_method_missing?, #map_tasks, #new, #rebind, #setup_instanciated_task, #to_coordination_task

Constructor Details

#initialize(variable_name, task_model) ⇒ TaskFromVariable

Returns a new instance of TaskFromVariable.



11
12
13
14
# File 'lib/roby/coordination/models/task_from_variable.rb', line 11

def initialize(variable_name, task_model)
    @variable_name = variable_name
    super(task_model)
end

Instance Attribute Details

#variable_nameObject (readonly)

Returns the value of attribute variable_name.



9
10
11
# File 'lib/roby/coordination/models/task_from_variable.rb', line 9

def variable_name
  @variable_name
end

Instance Method Details

#instanciate(plan, variables = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/roby/coordination/models/task_from_variable.rb', line 16

def instanciate(plan, variables = {})
    obj = variables[variable_name]
    unless obj.respond_to?(:as_plan)
        raise ArgumentError, "expected variable #{variable_name} to contain an object that can generate tasks, found #{obj}"
    end

    obj.as_plan
end

#to_sObject



25
26
27
# File 'lib/roby/coordination/models/task_from_variable.rb', line 25

def to_s
    "var(#{variable_name})[#{task_model}]"
end