Class: Roby::OpenStructModel
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Roby::OpenStructModel
- Defined in:
- lib/roby/state/open_struct_model.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Variable
Constant Summary
Constants inherited from OpenStruct
Roby::OpenStruct::FORBIDDEN_NAMES, Roby::OpenStruct::FORBIDDEN_NAMES_RX, Roby::OpenStruct::NOT_OVERRIDABLE, Roby::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
- #__get(name, create_substruct = true, &update) ⇒ Object
- #create_subfield(name) ⇒ Object
- #each_member(&block) ⇒ Object
-
#initialize(super_or_obj = nil, attach_to = nil, attach_name = nil) ⇒ OpenStructModel
constructor
A new instance of OpenStructModel.
- #respond_to_missing?(name, private = false) ⇒ Boolean
Methods inherited from OpenStruct
#__merge, #__parent, #__root, #__root?, #_dump, _load, #alias, #alias?, #attach, #attach_child, #attach_model, #attach_to, #attached?, #clear, #clear_model, #create_model, #delete, #detached!, #empty?, #filter, #freeze, #get, #global_filter, #has_method?, #link_to, #member?, #method_missing, #new_model, #on_change, #path, #pretty_print, #set, #stable!, #stable?, #to_hash, #update, #updated
Constructor Details
#initialize(super_or_obj = nil, attach_to = nil, attach_name = nil) ⇒ OpenStructModel
Returns a new instance of OpenStructModel.
47 48 49 50 |
# File 'lib/roby/state/open_struct_model.rb', line 47 def initialize(super_or_obj = nil, attach_to = nil, attach_name = nil) @superclass = super_or_obj super(nil, attach_to, attach_name) 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
6 7 8 |
# File 'lib/roby/state/open_struct_model.rb', line 6 def superclass @superclass end |
Instance Method Details
#__get(name, create_substruct = true, &update) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/roby/state/open_struct_model.rb', line 8 def __get(name, create_substruct = true, &update) if result = super(name, false, &update) result elsif superclass && (result = superclass.__get(name, false, &update)) if result.kind_of?(OpenStructModel) super(name, true, &update) else result end elsif create_substruct super end end |
#create_subfield(name) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/roby/state/open_struct_model.rb', line 30 def create_subfield(name) if superclass self.class.new(superclass.get(name), self, name) else self.class.new(nil, self, name) end end |
#each_member(&block) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/roby/state/open_struct_model.rb', line 38 def each_member(&block) super(&block) superclass&.each_member do |name, value| unless @members.has_key?(name) yield(name, value) end end end |
#respond_to_missing?(name, private = false) ⇒ Boolean
22 23 24 25 26 27 28 |
# File 'lib/roby/state/open_struct_model.rb', line 22 def respond_to_missing?(name, private = false) return true if super name = name.to_s name = name[0..-2] if name.end_with?("?") superclass&.member?(name) || superclass&.alias?(name) end |