Class: VContainer::SingletonProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/vcontainer/singleton_provider.rb

Overview

A singleton provider will only instantiate a type once

Instance Method Summary collapse

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

Returns:

  • (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