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
Constant Summary
Constants inherited from Buildable
Instance Attribute Summary
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.
-
#children ⇒ Array<Blueprints::Buildable>
Returns all direct children blueprints and namespaces of this namespace.
-
#demolish(environment) ⇒ 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, infer_name, #inspect, #path, #undo!
Constructor Details
#initialize(name, context) ⇒ Namespace
Creates namespace by name. See Buildable#new.
11 12 13 14 15 16 17 18 19 |
# File 'lib/blueprints/namespace.rb', line 11 def initialize(name, context) @children = Hash.new do |hash, search_key| pair = hash.detect do |name,| name.is_a?(Regexp) and search_key.to_s =~ name end hash[search_key] = BlueprintNameProxy.new(search_key, pair[1]) if pair end super(name, context) end |
Instance Method Details
#[](path) ⇒ Blueprints::Buildable
Finds child by relative name.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/blueprints/namespace.rb', line 38 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.
23 24 25 26 |
# File 'lib/blueprints/namespace.rb', line 23 def add_child(child) Blueprints.warn("Overwriting existing blueprint", child) if @children[child.name] @children[child.name] = child end |
#children ⇒ Array<Blueprints::Buildable>
Returns all direct children blueprints and namespaces of this namespace.
30 31 32 |
# File 'lib/blueprints/namespace.rb', line 30 def children @children.values end |
#demolish(environment) ⇒ Object
Demolishes all child blueprints and namespaces.
51 52 53 |
# File 'lib/blueprints/namespace.rb', line 51 def demolish(environment) @children.each_value { |blueprint| blueprint.demolish(environment) } end |