Module: DNApi::ComponentPossessor
Defined Under Namespace
Modules: Ext
Classes: ComponentAttachmentError
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(receiver) ⇒ Object
34
35
36
37
|
# File 'lib/dnapi/component_possessor.rb', line 34
def self.included(receiver)
receiver.extend(Ext)
receiver.send :many, :components
end
|
Instance Method Details
#add_component(key, component_options = {}) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/dnapi/component_possessor.rb', line 39
def add_component(key, component_options={})
unless klass = Component[key.to_sym]
raise Component::NoSuchComponent, "unknown component #{key.inspect}"
end
c = klass.new(component_options.merge(:parent => self))
unless c.can_belong_to?(self)
raise ComponentAttachmentError, "Can't attach #{key.inspect} to a #{self.class}"
end
components << c
c
end
|
#component(key) ⇒ Object
25
26
27
|
# File 'lib/dnapi/component_possessor.rb', line 25
def component(key)
components.detect {|c| c.key == key }
end
|
#component_group(group_key) ⇒ Object
29
30
31
32
|
# File 'lib/dnapi/component_possessor.rb', line 29
def component_group(group_key)
component_keys = self::class.component_group_map[group_key.to_sym] || []
component_keys.map {|key| components.select {|c| c.key == key } }.flatten
end
|
#has_component?(key) ⇒ Boolean
Also known as:
component?
19
20
21
|
# File 'lib/dnapi/component_possessor.rb', line 19
def has_component?(key)
components.any? {|c| c.key == key }
end
|