Class: VContainer::SingletonProvider
- Inherits:
-
Object
- Object
- VContainer::SingletonProvider
- Defined in:
- lib/vcontainer/singleton_provider.rb
Overview
A singleton provider will only instantiate a type once
Instance Method Summary collapse
- #build(what, container = NilContainer.new) ⇒ Object
- #can_handle?(what) ⇒ Boolean
-
#initialize(build_type) ⇒ SingletonProvider
constructor
A new instance of SingletonProvider.
Constructor Details
#initialize(build_type) ⇒ SingletonProvider
Returns a new instance of SingletonProvider.
6 7 8 |
# File 'lib/vcontainer/singleton_provider.rb', line 6 def initialize(build_type) @type = build_type end |
Instance Method Details
#build(what, container = NilContainer.new) ⇒ Object
10 11 12 |
# File 'lib/vcontainer/singleton_provider.rb', line 10 def build(what, container = NilContainer.new) @cached_instance ||= instantiate(container) end |
#can_handle?(what) ⇒ Boolean
14 15 16 17 |
# File 'lib/vcontainer/singleton_provider.rb', line 14 def can_handle?(what) expected = what.to_s.camelize.constantize @type.ancestors.include?(expected) end |