Class: DiFtw::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/diftw/provider.rb

Overview

Class that provides a dependency via a “call” method. It may optionally depend on other dependencies, which will be available as methods inside the given Proc.

Instance Method Summary collapse

Constructor Details

#initialize(injector, name, y, deps = []) ⇒ Provider

Returns a new instance of Provider.

Parameters:

  • injector (DiFtw::Injection)
  • name (Symbol)
  • y (Proc)
  • deps (Array<Symbol]) (defaults to: [])

    eps [Array<Symbol]



13
14
15
16
# File 'lib/diftw/provider.rb', line 13

def initialize(injector, name, y, deps = [])
  @name, @y = name, y
  injector.inject_instance self, *deps if deps.any?
end

Instance Method Details

#callObject

Executes the proc and returns the dependency



19
20
21
# File 'lib/diftw/provider.rb', line 19

def call
  self.instance_exec(&@y)
end