Class: Pharrell::Config
- Inherits:
-
Object
- Object
- Pharrell::Config
- Defined in:
- lib/pharrell/config.rb
Defined Under Namespace
Classes: ObjectGenerator
Instance Method Summary collapse
- #bind(klass, arg = nil, &blk) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #instance_for(klass) ⇒ Object
- #rebuild! ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
3 4 5 |
# File 'lib/pharrell/config.rb', line 3 def initialize @map = {} end |
Instance Method Details
#bind(klass, arg = nil, &blk) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/pharrell/config.rb', line 7 def bind(klass, arg = nil, &blk) if blk = arg.kind_of?(Hash) ? arg : {} @map[klass] = ObjectGenerator.new(, &blk) else @map[klass] = arg end end |
#instance_for(klass) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pharrell/config.rb', line 16 def instance_for(klass) instance_or_class = @map[klass] if instance_or_class.is_a? Class instance_or_class.new elsif instance_or_class.is_a? ObjectGenerator instance_or_class.fetch else instance_or_class end end |
#rebuild! ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/pharrell/config.rb', line 28 def rebuild! @map.each do |key, value| if value.is_a? ObjectGenerator value.invalidate! end end end |