Class: Callme::Scopes::RequestScope

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

Overview

Request scope instantiates new dep instance on each new HTTP request

Instance Method Summary collapse

Constructor Details

#initialize(dep_factory) ⇒ RequestScope

Constructon

Parameters:

  • dep_factory

    dep factory



9
10
11
# File 'lib/callme/scopes/request_scope.rb', line 9

def initialize(dep_factory)
  @dep_factory = dep_factory
end

Instance Method Details

#delete_dep(dep_metadata) ⇒ Object

Delete dep from scope

Parameters:



25
26
27
# File 'lib/callme/scopes/request_scope.rb', line 25

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

#get_dep(dep_metadata) ⇒ Object

Returns a dep from the RequestStore RequestStore is a wrapper for Thread.current which clears it on each new HTTP request

Parameters:



19
20
21
# File 'lib/callme/scopes/request_scope.rb', line 19

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