Class: Babushka::DepPool

Inherits:
Object show all
Defined in:
lib/babushka/dep_pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ DepPool

Returns a new instance of DepPool.


4
5
6
7
# File 'lib/babushka/dep_pool.rb', line 4

def initialize source
  clear!
  @source = source
end

Instance Method Details

#add_dep(name, params, block) ⇒ Object


25
26
27
28
29
30
# File 'lib/babushka/dep_pool.rb', line 25

def add_dep name, params, block
  self.for(name) || begin
    opts = params.extract_options!
    Dep.new name, @source, params, opts, block
  end
end

#add_template(name, block) ⇒ Object


32
33
34
# File 'lib/babushka/dep_pool.rb', line 32

def add_template name, block
  DepTemplate.for name, @source, &block
end

#clear!Object


36
37
38
# File 'lib/babushka/dep_pool.rb', line 36

def clear!
  @pool = {}
end

#countObject


9
10
11
# File 'lib/babushka/dep_pool.rb', line 9

def count
  @pool.length
end

#for(spec) ⇒ Object


21
22
23
# File 'lib/babushka/dep_pool.rb', line 21

def for spec
  spec.respond_to?(:name) ? @pool[spec.name] : @pool[spec]
end

#itemsObject


17
18
19
# File 'lib/babushka/dep_pool.rb', line 17

def items
  @pool.values
end

#namesObject


13
14
15
# File 'lib/babushka/dep_pool.rb', line 13

def names
  @pool.keys
end

#register(item) ⇒ Object


40
41
42
43
# File 'lib/babushka/dep_pool.rb', line 40

def register item
  raise "Already registered '#{item.name}'." if @pool.has_key?(item.name)
  @pool[item.name] = item
end