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, #__respond_to__, #create_subfield, #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, #create_model, #create_subfield, #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(super_or_obj = nil, attach_to = nil, attach_name = nil) ⇒ StateModel
Returns a new instance of StateModel.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/roby/state/state_model.rb', line 45 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
39 40 41 |
# File 'lib/roby/state/state_model.rb', line 39 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
59 60 61 62 63 64 65 66 67 |
# File 'lib/roby/state/state_model.rb', line 59 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
41 42 43 |
# File 'lib/roby/state/state_model.rb', line 41 def to_s "#<StateModel:#{object_id} path=#{path.join("/")} fields=#{@members.keys.sort.join(",")}>" end |