Class: Codeine::Container
- Inherits:
-
Object
- Object
- Codeine::Container
- Defined in:
- lib/codeine/container.rb
Instance Method Summary collapse
- #configure {|_self| ... } ⇒ Object
- #filter(pattern, &block) ⇒ Object
- #filters ⇒ Object
- #get(key, args = []) ⇒ Object (also: #[])
- #register(key, &block) ⇒ Object
- #services ⇒ Object
Instance Method Details
#configure {|_self| ... } ⇒ Object
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 |
#filters ⇒ Object
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 |
#services ⇒ Object
5 6 7 |
# File 'lib/codeine/container.rb', line 5 def services @services ||= {} end |