Class: Roby::StateModel
- Inherits:
-
OpenStructModel
- Object
- OpenStruct
- OpenStructModel
- Roby::StateModel
- Defined in:
- lib/roby/state/state_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 collapse
-
#superclass ⇒ Object
readonly
Returns the superclass, i.e.
Attributes inherited from OpenStruct
#__parent_name, #__parent_struct, #model
Instance Method Summary collapse
-
#initialize(super_or_obj = nil, attach_to = nil, attach_name = nil) ⇒ StateModel
constructor
A new instance of StateModel.
-
#resolve_data_sources(object, state) ⇒ Object
This methods iterates over the state model, and for each state variable for which a data source model is provided, create the corresponding data source by calling #resolve.
- #to_s ⇒ Object
Methods inherited from OpenStructModel
#__get, #create_subfield, #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, #create_model, #create_subfield, #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(super_or_obj = nil, attach_to = nil, attach_name = nil) ⇒ StateModel
Returns a new instance of StateModel.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/roby/state/state_model.rb', line 48 def initialize(super_or_obj = nil, attach_to = nil, attach_name = nil) super(super_or_obj, attach_to, attach_name) global_filter do |name, value| if value.respond_to?(:to_state_variable_model) value.to_state_variable_model(self, name) else raise ArgumentError, "cannot set #{value} on #{name} in a state model. "\ "Only allowed values are StateVariableModel, and values "\ "that respond to #to_state_variable_model" end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Roby::OpenStruct
Instance Attribute Details
#superclass ⇒ Object (readonly)
Returns the superclass, i.e. the state model this is a refinement on
41 42 43 |
# File 'lib/roby/state/state_model.rb', line 41 def superclass @superclass end |
Instance Method Details
#resolve_data_sources(object, state) ⇒ Object
This methods iterates over the state model, and for each state variable for which a data source model is provided, create the corresponding data source by calling #resolve
65 66 67 68 69 70 71 72 73 |
# File 'lib/roby/state/state_model.rb', line 65 def resolve_data_sources(object, state) each_member do |name, field| if field.respond_to?(:data_source) state.data_sources.set(name, field.data_source.resolve(object)) else field.resolve_data_sources(object, state.__get(name, true)) end end end |
#to_s ⇒ Object
43 44 45 46 |
# File 'lib/roby/state/state_model.rb', line 43 def to_s "#<StateModel:#{object_id} path=#{path.join('/')} "\ "fields=#{@members.keys.sort.join(',')}>" end |