Sha256: ea3f5d5aba2d13eb0ef569c5cb5ac830d19595f241209e030c845c2bec9fecfa

Contents?: true

Size: 688 Bytes

Versions: 1

Compression:

Stored size: 688 Bytes

Contents

module Blueprints
  class Namespace < Buildable
    cattr_accessor :root
    delegate :empty?, :size, :to => :@children

    def initialize(name)
      super(name)
      @children = {}
    end

    def add_child(child)
      #TODO: Raise error for duplicate children!
      @children[child.name] = child
      child.namespace = self
    end

    def [](path)
      child_name, path = path.to_s.split('.', 2)
      child = @children[child_name.to_sym] or raise PlanNotFoundError, child_name
      if path
        child[path]
      else
        child
      end
    end

    def build_plan
      Namespace.root.add_variable(name, @children.collect {|p| p.last.build }.uniq)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blueprints-0.3.0 lib/blueprints/namespace.rb