Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/orogen/base.rb

Instance Method Summary collapse

Instance Method Details

#enumerate_inherited_map(each_name, attribute_name = each_name) ⇒ Object

:nodoc:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/orogen/base.rb', line 35

def enumerate_inherited_map(each_name, attribute_name = each_name) # :nodoc:
    class_eval <<-EOD, __FILE__, __LINE__
    attr_reader :#{attribute_name}
    def all_#{attribute_name}; each_#{each_name}.to_a end
    def self_#{attribute_name}; @#{attribute_name}.values end
    def has_#{attribute_name}?(name); !!find_#{each_name}(name) end

    def find_#{each_name}(name)
        name = name.to_str
        if v = @#{attribute_name}[name]
            v
        elsif superclass
            superclass.find_#{each_name}(name)
        end
    end
    def each_#{each_name}(&block)
        if block_given?
            if superclass
                superclass.each_#{each_name}(&block)
            end
            @#{attribute_name}.each_value(&block)
        else
            enum_for(:each_#{each_name})
        end
    end
    EOD
end

#enumerate_inherited_set(each_name, attribute_name = each_name) ⇒ Object

:nodoc:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/orogen/base.rb', line 13

def enumerate_inherited_set(each_name, attribute_name = each_name) # :nodoc:
    class_eval <<-EOD, __FILE__, __LINE__
    def find_#{attribute_name}(name) 
        each_#{each_name} do |n|
            return n if n.name == name
        end
    end
    def all_#{attribute_name}; each_#{each_name}.to_a end
    def self_#{attribute_name}; @#{attribute_name} end
    def each_#{each_name}(&block)
        if block_given?
            if superclass
                superclass.each_#{each_name}(&block)
            end
            @#{attribute_name}.each(&block)
        else
            enum_for(:each_#{each_name})
        end
    end
    EOD
end