Class: SmartIoC::Scopes::Singleton

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_ioc/scopes/singleton.rb

Overview

Singleton scope returns same bean instance on each call

Direct Known Subclasses

Request

Constant Summary collapse

VALUE =
:singleton

Instance Method Summary collapse

Constructor Details

#initializeSingleton

Returns a new instance of Singleton.



5
6
7
# File 'lib/smart_ioc/scopes/singleton.rb', line 5

def initialize
  @beans = {}
end

Instance Method Details

#clearObject



23
24
25
# File 'lib/smart_ioc/scopes/singleton.rb', line 23

def clear
  # do nothing as singleton beans are being instantiated only once
end

#force_clearObject



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

def force_clear
  @beans = {}
  nil
end

#get_bean(klass) ⇒ Object

Parameters:

  • klass (Class)

    bean class



11
12
13
# File 'lib/smart_ioc/scopes/singleton.rb', line 11

def get_bean(klass)
  @beans[klass]
end

#save_bean(klass, bean) ⇒ Object

Parameters:

  • klass (Class)

    bean class

  • bean (Any Object)

    bean object



18
19
20
21
# File 'lib/smart_ioc/scopes/singleton.rb', line 18

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