Class: VContainer::SimpleProvider

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

Overview

A simple provider will instantiate a type everytime its required

Instance Method Summary collapse

Constructor Details

#initialize(build_type) ⇒ SimpleProvider

Returns a new instance of SimpleProvider.



6
7
8
# File 'lib/vcontainer/simple_provider.rb', line 6

def initialize(build_type)
  @type = build_type
end

Instance Method Details

#build(what, container = NilContainer.new) ⇒ Object



10
11
12
13
# File 'lib/vcontainer/simple_provider.rb', line 10

def build(what, container = NilContainer.new)
  values = container.provide_for_method(@type.instance_method(:initialize))
  @type.new *values
end

#can_handle?(what) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/vcontainer/simple_provider.rb', line 15

def can_handle?(what)
  expected = what.to_s.camelize.constantize
  @type.ancestors.include?(expected)
end