Class: Callme::Scopes::SingletonScope

Inherits:
Object
  • Object
show all
Defined in:
lib/callme/scopes/singleton_scope.rb

Overview

Singleton scope returns the same dep instance on each call

Instance Method Summary collapse

Constructor Details

#initialize(dep_factory) ⇒ SingletonScope

Constructon

Parameters:

  • dep_factory

    dep factory



7
8
9
# File 'lib/callme/scopes/singleton_scope.rb', line 7

def initialize(dep_factory)
  @dep_factory = dep_factory
end

Instance Method Details

#delete_dep(dep_metadata) ⇒ Object

Delete dep from scope

Parameters:



21
22
23
# File 'lib/callme/scopes/singleton_scope.rb', line 21

def delete_dep()
  store.delete(.name)
end

#get_dep(dep_metadata) ⇒ Object

Returns the same dep instance on each call

Parameters:



15
16
17
# File 'lib/callme/scopes/singleton_scope.rb', line 15

def get_dep()
  store[.name] || @dep_factory.create_dep_and_save(, store)
end