Class: Codeine::Container

Inherits:
Object
  • Object
show all
Defined in:
lib/codeine/container.rb

Instance Method Summary collapse

Instance Method Details

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



33
34
35
# File 'lib/codeine/container.rb', line 33

def configure
  yield self
end

#filter(pattern, &block) ⇒ Object



29
30
31
# File 'lib/codeine/container.rb', line 29

def filter(pattern, &block)
  filters.push :pattern => pattern, :block => block
end

#filtersObject



9
10
11
# File 'lib/codeine/container.rb', line 9

def filters
  @filters ||= []
end

#get(key, args = []) ⇒ Object Also known as: []



17
18
19
20
21
22
23
24
25
26
# File 'lib/codeine/container.rb', line 17

def get(key, args = [])
  key = key.to_sym
  service = services[key].call(*args)
  filters.each do |f|
    if key.to_s =~ f[:pattern]
      f[:block].call(key, service)
    end
  end
  service
end

#register(key, &block) ⇒ Object



13
14
15
# File 'lib/codeine/container.rb', line 13

def register(key, &block)
  services[key.to_sym] = block
end

#servicesObject



5
6
7
# File 'lib/codeine/container.rb', line 5

def services
  @services ||= {}
end