Class: Blueprints::Namespace
- Defined in:
- lib/blueprints/namespace.rb
Overview
Namespace class, inherits from Buildable
. Allows adding and finding child blueprints/namespaces and building all it’s children.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Attributes inherited from Buildable
Instance Method Summary collapse
-
#[](path) ⇒ Object
Finds child by relative name.
-
#add_child(child) ⇒ Object
Adds child to namespaces children.
-
#build_self(build_once = true) ⇒ Object
Builds all children and sets instance variable named by name of namespace with the results.
-
#demolish ⇒ Object
Demolished all child blueprints and namespaces.
-
#initialize(name) ⇒ Namespace
constructor
Creates namespace by name.
Methods inherited from Buildable
#attributes, #build, #build_parents, #built?, #depends_on, normalize_attributes, #normalized_attributes, #result, #result=, #undo!
Constructor Details
#initialize(name) ⇒ Namespace
Creates namespace by name. See Buildable#new.
10 11 12 13 |
# File 'lib/blueprints/namespace.rb', line 10 def initialize(name) super(name) @children = {} end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
6 7 8 |
# File 'lib/blueprints/namespace.rb', line 6 def children @children end |
Instance Method Details
#[](path) ⇒ Object
Finds child by relative name. Raises BlueprintNotFoundError if child can’t be found.
22 23 24 25 26 27 28 29 30 |
# File 'lib/blueprints/namespace.rb', line 22 def [](path) child_name, path = path.to_s.split('.', 2) child = @children[child_name.to_sym] or raise BlueprintNotFoundError, child_name if path child[path] else child end end |
#add_child(child) ⇒ Object
Adds child to namespaces children. Child should be instance of Buildable.
16 17 18 19 |
# File 'lib/blueprints/namespace.rb', line 16 def add_child(child) @children[child.name] = child child.namespace = self end |
#build_self(build_once = true) ⇒ Object
Builds all children and sets instance variable named by name of namespace with the results.
33 34 35 |
# File 'lib/blueprints/namespace.rb', line 33 def build_self(build_once = true) self.result = @children.collect {|p| p.last.build }.uniq end |
#demolish ⇒ Object
Demolished all child blueprints and namespaces
38 39 40 |
# File 'lib/blueprints/namespace.rb', line 38 def demolish @children.each_value(&:demolish) end |