module Barn::Namespace

Public Instance Methods

build(name, build_options = {}) click to toggle source
# File lib/barn/namespace.rb, line 8
def build(name, build_options = {})
  factory = factories[name]

  chained_builder = build_chain.reverse.reduce(factory) do |final, builder|
    builder.new(final)
  end  # not caching this for simplicity

  chained_builder.call \
    :factory => factory,
    :args    => build_options
end
build_chain() click to toggle source
# File lib/barn/namespace.rb, line 20
def build_chain
  @build_chain ||= [Barn::Builders::Hash]
end
define(name, factory_options = {}, &blk) click to toggle source
# File lib/barn/namespace.rb, line 3
def define(name, factory_options = {}, &blk)
  blk ||= Proc.new {}
  factories[name] = Factory.new(name, factory_options, &blk)
end
factories() click to toggle source
# File lib/barn/namespace.rb, line 24
def factories
  @factories ||= {}
end
reset() click to toggle source
# File lib/barn/namespace.rb, line 28
def reset
  @computed_chain = nil
  @factories = {}
end