Class: Roby::GoalModel

Inherits:
OpenStructModel show all
Defined in:
lib/roby/state/goal_model.rb

Overview

Representation of a level in the state model

Constant Summary

Constants inherited from OpenStruct

OpenStruct::FORBIDDEN_NAMES, OpenStruct::FORBIDDEN_NAMES_RX, OpenStruct::NOT_OVERRIDABLE, OpenStruct::NOT_OVERRIDABLE_RX

Instance Attribute Summary

Attributes inherited from OpenStructModel

#superclass

Attributes inherited from OpenStruct

#__parent_name, #__parent_struct, #model

Instance Method Summary collapse

Methods inherited from OpenStructModel

#__get, #__respond_to__, #each_member

Methods inherited from OpenStruct

#__get, #__merge, #__parent, #__respond_to__, #__root, #__root?, #_dump, _load, #alias, #attach, #attach_child, #attach_model, #attach_to, #attached?, #clear, #clear_model, #delete, #detached!, #each_member, #empty?, #filter, #freeze, #get, #global_filter, #has_method?, #link_to, #method_missing, #new_model, #on_change, #path, #pretty_print, #respond_to?, #set, #stable!, #stable?, #to_hash, #update, #updated

Constructor Details

#initialize(state_model = nil, superclass = nil, attach_to = nil, attach_name = nil) ⇒ GoalModel

Returns a new instance of GoalModel.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/roby/state/goal_model.rb', line 33

def initialize(state_model = nil, superclass = nil, attach_to = nil, attach_name = nil)
    super(superclass, attach_to, attach_name)

    @model = state_model
    if @model
        attach_model
    end

    global_filter do |name, value|
        if value.respond_to?(:to_goal_variable_model)
            value.to_goal_variable_model(self, name)
        else
            raise ArgumentError, "cannot set #{value} on #{name} in a goal model. Only allowed values are GoalVariableModel, and values that respond to #to_goal_variable_model"
        end
    end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Roby::OpenStruct

Instance Method Details

#create_modelObject



50
51
52
# File 'lib/roby/state/goal_model.rb', line 50

def create_model
    GoalModel.new
end

#create_subfield(name) ⇒ Object



54
55
56
57
58
# File 'lib/roby/state/goal_model.rb', line 54

def create_subfield(name)
    superklass = if superclass then superclass.get(name) end
    supermodel = if model then model.get(name) end
    self.class.new(supermodel, superklass, self, name)
end

#resolve_goals(obj, space) ⇒ Object

Once the task is completely instanciated, we should be able to determine its goal



62
63
64
65
66
67
68
69
70
# File 'lib/roby/state/goal_model.rb', line 62

def resolve_goals(obj, space)
    each_member do |name, value|
        if value.respond_to?(:resolve_goals)
            value.resolve_goals(obj, space.get(name))
        else
            space.set(name, value.call(obj))
        end
    end
end