Class: Freightrain::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/freightrain/ioc/registry.rb

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



6
7
8
9
# File 'lib/freightrain/ioc/registry.rb', line 6

def initialize
  @classes = {}
  @cache = {}      
end

Instance Method Details

#register(klass, options) ⇒ Object



11
12
13
14
# File 'lib/freightrain/ioc/registry.rb', line 11

def register(klass, options)      
  @classes[klass.name.to_convention_sym] = klass
  @cache[klass.name.to_convention_sym] = klass.new if options[:model] == :singleton            
end

#resolve(class_name) ⇒ Object



16
17
18
19
# File 'lib/freightrain/ioc/registry.rb', line 16

def resolve(class_name)
  raise "Could not instance class #{class_name}" unless @classes.has_key?(class_name)
  return @cache[class_name] || @classes[class_name].new
end