Class: SmartIoC::Scopes::Request

Inherits:
Singleton show all
Defined in:
lib/smart_ioc/scopes/request.rb

Overview

Request scope instantiates new bean instance if it’s not present in Thread.current

Constant Summary collapse

VALUE =
:request
KEY =
:__SmartIoC

Instance Method Summary collapse

Constructor Details

#initializeRequest

Returns a new instance of Request.

Parameters:

  • bean_factory

    bean factory



7
8
9
# File 'lib/smart_ioc/scopes/request.rb', line 7

def initialize
  clear
end

Instance Method Details

#clearObject



26
27
28
29
30
# File 'lib/smart_ioc/scopes/request.rb', line 26

def clear
  Thread.current[KEY] = {}
  @beans = Thread.current[KEY]
  nil
end

#force_clearObject



32
33
34
# File 'lib/smart_ioc/scopes/request.rb', line 32

def force_clear
  clear
end

#get_bean(klass) ⇒ Object

Parameters:

  • klass (Class)

    bean class



14
15
16
# File 'lib/smart_ioc/scopes/request.rb', line 14

def get_bean(klass)
  @beans[klass]
end

#save_bean(klass, bean) ⇒ Object

Parameters:

  • klass (Class)

    bean class

  • bean (Any Object)

    bean object



21
22
23
24
# File 'lib/smart_ioc/scopes/request.rb', line 21

def save_bean(klass, bean)
  @beans[klass] = bean
  nil
end