Class: RgGen::Core::Base::Component
- Inherits:
-
Object
- Object
- RgGen::Core::Base::Component
show all
- Defined in:
- lib/rggen/core/base/component.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(parent, base_name, layer, *args) ⇒ Component
Returns a new instance of Component.
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/rggen/core/base/component.rb', line 7
def initialize(parent, base_name, layer, *args)
@parent = parent
@base_name = base_name
@layer = layer
@children = []
@need_children = true
@features = {}
@depth = (parent&.depth || 0) + 1
@component_index = parent&.children&.size || 0
post_initialize(*args)
block_given? && yield(self)
end
|
Instance Attribute Details
Returns the value of attribute children.
22
23
24
|
# File 'lib/rggen/core/base/component.rb', line 22
def children
@children
end
|
#component_index ⇒ Object
Returns the value of attribute component_index.
24
25
26
|
# File 'lib/rggen/core/base/component.rb', line 24
def component_index
@component_index
end
|
Returns the value of attribute depth.
23
24
25
|
# File 'lib/rggen/core/base/component.rb', line 23
def depth
@depth
end
|
Returns the value of attribute layer.
21
22
23
|
# File 'lib/rggen/core/base/component.rb', line 21
def layer
@layer
end
|
Returns the value of attribute parent.
20
21
22
|
# File 'lib/rggen/core/base/component.rb', line 20
def parent
@parent
end
|
Instance Method Details
#add_child(child) ⇒ Object
50
51
52
|
# File 'lib/rggen/core/base/component.rb', line 50
def add_child(child)
need_children? && (children << child)
end
|
#add_feature(feature) ⇒ Object
54
55
56
|
# File 'lib/rggen/core/base/component.rb', line 54
def add_feature(feature)
@features[feature.feature_name] = feature
end
|
#ancestors ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/rggen/core/base/component.rb', line 26
def ancestors
[].tap do |components|
component = self
while component
components.unshift(component)
component = component.parent
end
end
end
|
#component_name ⇒ Object
Also known as:
to_s
36
37
38
|
# File 'lib/rggen/core/base/component.rb', line 36
def component_name
[@layer, @base_name].compact.join('@')
end
|
#feature(key) ⇒ Object
62
63
64
|
# File 'lib/rggen/core/base/component.rb', line 62
def feature(key)
@features[key]
end
|
58
59
60
|
# File 'lib/rggen/core/base/component.rb', line 58
def features
@features.values
end
|
#need_children? ⇒ Boolean
42
43
44
|
# File 'lib/rggen/core/base/component.rb', line 42
def need_children?
@need_children
end
|
#need_no_children ⇒ Object
46
47
48
|
# File 'lib/rggen/core/base/component.rb', line 46
def need_no_children
@need_children = false
end
|