Module: Barn::Namespace

Included in:
Barn
Defined in:
lib/barn/namespace.rb

Instance Method Summary collapse

Instance Method Details

#build(name, build_options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# 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_chainObject



20
21
22
# File 'lib/barn/namespace.rb', line 20

def build_chain
  @build_chain ||= [Barn::Builders::Hash]
end

#define(name, factory_options = {}, &blk) ⇒ Object



3
4
5
6
# 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

#factoriesObject



24
25
26
# File 'lib/barn/namespace.rb', line 24

def factories
  @factories ||= {}
end

#resetObject



28
29
30
31
# File 'lib/barn/namespace.rb', line 28

def reset
  @computed_chain = nil
  @factories = {}
end