Class: IocRb::Scopes::SingletonScope

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

Overview

Singleton scope returns the same bean instance on each call

Instance Method Summary collapse

Constructor Details

#initialize(bean_factory) ⇒ SingletonScope

Constructon

Parameters:

  • bean_factory

    bean factory



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

def initialize(bean_factory)
  @beans = {}
  @bean_factory = bean_factory
end

Instance Method Details

#delete_bean(bean_metadata) ⇒ Object

Delete bean from scope

Parameters:



26
27
28
# File 'lib/ioc_rb/scopes/singleton_scope.rb', line 26

def delete_bean()
  @beans.delete(.name)
end

#get_bean(bean_metadata) ⇒ Object

Returns the same bean instance on each call

Parameters:



16
17
18
19
20
21
22
# File 'lib/ioc_rb/scopes/singleton_scope.rb', line 16

def get_bean()
  if bean = @beans[.name]
    bean
  else
    @bean_factory.create_bean_and_save(, @beans)
  end
end