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) ⇒ Blueprints::Buildable
Finds child by relative name.
-
#add_child(child) ⇒ Object
Adds child to namespaces children.
-
#build_self(eval_context, build_once, options) ⇒ Array
Builds all children and sets an instance variable named by name of namespace with the results.
-
#demolish(eval_context) ⇒ Object
Demolishes all child blueprints and namespaces.
-
#initialize(name, context) ⇒ Namespace
constructor
Creates namespace by name.
Methods inherited from Buildable
#attributes, #build, #build_parents, #built?, #depends_on, #full_name, #inspect, #path, #undo!
Constructor Details
#initialize(name, context) ⇒ Namespace
Creates namespace by name. See Buildable#new.
12 13 14 15 |
# File 'lib/blueprints/namespace.rb', line 12 def initialize(name, context) @children = {} super(name, context) 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) ⇒ Blueprints::Buildable
Finds child by relative name.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/blueprints/namespace.rb', line 28 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. Warns if this will overwrite existing child.
19 20 21 22 |
# File 'lib/blueprints/namespace.rb', line 19 def add_child(child) Blueprints.warn("Overwriting existing blueprint", child) if @children[child.name] @children[child.name] = child end |
#build_self(eval_context, build_once, options) ⇒ Array
Builds all children and sets an instance variable named by name of namespace with the results.
44 45 46 |
# File 'lib/blueprints/namespace.rb', line 44 def build_self(eval_context, build_once, ) result(eval_context) { @children.values.collect { |child| child.build(eval_context, build_once, ) }.uniq } end |
#demolish(eval_context) ⇒ Object
Demolishes all child blueprints and namespaces.
50 51 52 |
# File 'lib/blueprints/namespace.rb', line 50 def demolish(eval_context) @children.each_value { |blueprint| blueprint.demolish(eval_context) } end |