Sha256: 55b1329fb61de12e839c58b9964c9a50983b870c70d276df52a5ea984e2abbf4
Contents?: true
Size: 1.22 KB
Versions: 2
Compression:
Stored size: 1.22 KB
Contents
module Blueprints # Namespace class, inherits from <tt>Buildable</tt>. Allows adding and finding child blueprints/namespaces and building # all it's children. class Namespace < Buildable cattr_accessor :root attr_reader :children delegate :empty?, :size, :to => :@children # Creates namespace by name. See Buildable#new. def initialize(name) super(name) @children = {} end # Adds child to namespaces children. Child should be instance of Buildable. def add_child(child) @children[child.name] = child child.namespace = self end # Finds child by relative name. Raises BlueprintNotFoundError if child can't be found. 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 # Builds all children and sets instance variable named by name of namespace with the results. def build_self(build_once = true) self.result = @children.collect {|p| p.last.build }.uniq end # Demolished all child blueprints and namespaces def demolish @children.each_value(&:demolish) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
blueprints-0.8.2 | lib/blueprints/namespace.rb |
blueprints-0.8.1 | lib/blueprints/namespace.rb |