Class: Roby::GoalModel
- Inherits:
-
OpenStructModel
- Object
- OpenStruct
- OpenStructModel
- Roby::GoalModel
- 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
Attributes inherited from OpenStruct
#__parent_name, #__parent_struct, #model
Instance Method Summary collapse
- #create_model ⇒ Object
- #create_subfield(name) ⇒ Object
-
#initialize(state_model = nil, superclass = nil, attach_to = nil, attach_name = nil) ⇒ GoalModel
constructor
rubocop:disable Metrics/ParameterLists.
-
#resolve_goals(obj, space) ⇒ Object
Once the task is completely instanciated, we should be able to determine its goal.
Methods inherited from OpenStructModel
#__get, #each_member, #respond_to_missing?
Methods inherited from OpenStruct
#__get, #__merge, #__parent, #__root, #__root?, #_dump, _load, #alias, #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, #member?, #method_missing, #new_model, #on_change, #path, #pretty_print, #respond_to_missing?, #set, #stable!, #stable?, #to_hash, #update, #updated
Constructor Details
#initialize(state_model = nil, superclass = nil, attach_to = nil, attach_name = nil) ⇒ GoalModel
rubocop:disable Metrics/ParameterLists
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/roby/state/goal_model.rb', line 35 def initialize(state_model = nil, superclass = nil, attach_to = nil, attach_name = nil) # rubocop:disable Metrics/ParameterLists 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_model ⇒ Object
55 56 57 |
# File 'lib/roby/state/goal_model.rb', line 55 def create_model GoalModel.new end |
#create_subfield(name) ⇒ Object
59 60 61 62 63 |
# File 'lib/roby/state/goal_model.rb', line 59 def create_subfield(name) superklass = superclass&.get(name) supermodel = model&.get(name) 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
67 68 69 70 71 72 73 74 75 |
# File 'lib/roby/state/goal_model.rb', line 67 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 |