Class: Roby::OpenStructModel

Inherits:
OpenStruct show all
Defined in:
lib/roby/state/open_struct_model.rb

Direct Known Subclasses

GoalModel, StateModel

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

Attributes inherited from OpenStruct

#__parent_name, #__parent_struct, #model

Instance Method Summary collapse

Methods inherited from OpenStruct

#__merge, #__parent, #__root, #__root?, #_dump, _load, #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, #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) ⇒ OpenStructModel

Returns a new instance of OpenStructModel.



42
43
44
45
# File 'lib/roby/state/open_struct_model.rb', line 42

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

#superclassObject (readonly)

Returns the superclass, i.e. the state model this is a refinement on



4
5
6
# File 'lib/roby/state/open_struct_model.rb', line 4

def superclass
  @superclass
end

Instance Method Details

#__get(name, create_substruct = true, &update) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/roby/state/open_struct_model.rb', line 6

def __get(name, create_substruct = true, &update)
    if result = super(name, false, &update)
        return result
    elsif superclass && (result = superclass.__get(name, false, &update))
        if result.kind_of?(OpenStructModel)
            return super(name, true, &update)
        else return result
        end
    elsif create_substruct
        return super
    end
end

#__respond_to__(name) ⇒ Object



19
20
21
# File 'lib/roby/state/open_struct_model.rb', line 19

def __respond_to__(name)
    super || (superclass.__respond_to__(name) if superclass)
end

#create_subfield(name) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/roby/state/open_struct_model.rb', line 23

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



31
32
33
34
35
36
37
38
39
40
# File 'lib/roby/state/open_struct_model.rb', line 31

def each_member(&block)
    super(&block)
    if superclass
        superclass.each_member do |name, value|
            if !@members.has_key?(name)
                yield(name, value)
            end
        end
    end
end