Class: Fabrique::BeanFactory
- Inherits:
-
Object
- Object
- Fabrique::BeanFactory
- Defined in:
- lib/fabrique/bean_factory.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#singletons ⇒ Object
readonly
Returns the value of attribute singletons.
Instance Method Summary collapse
- #get_bean(bean_name) ⇒ Object
-
#initialize(registry) ⇒ BeanFactory
constructor
A new instance of BeanFactory.
- #load_gem_dependencies ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(registry) ⇒ BeanFactory
Returns a new instance of BeanFactory.
8 9 10 11 12 13 14 |
# File 'lib/fabrique/bean_factory.rb', line 8 def initialize(registry) @registry = registry @registry.validate! @gem_loader = GemLoader.new(@registry.get_gem_definitions) @singletons = {} @semaphore = Mutex.new end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
6 7 8 |
# File 'lib/fabrique/bean_factory.rb', line 6 def registry @registry end |
#singletons ⇒ Object (readonly)
Returns the value of attribute singletons.
6 7 8 |
# File 'lib/fabrique/bean_factory.rb', line 6 def singletons @singletons end |
Instance Method Details
#get_bean(bean_name) ⇒ Object
16 17 18 19 20 |
# File 'lib/fabrique/bean_factory.rb', line 16 def get_bean(bean_name) @semaphore.synchronize do get_bean_unsynchronized(bean_name) end end |
#load_gem_dependencies ⇒ Object
22 23 24 |
# File 'lib/fabrique/bean_factory.rb', line 22 def load_gem_dependencies @gem_loader.load_gems end |
#to_h ⇒ Object
26 27 28 29 30 |
# File 'lib/fabrique/bean_factory.rb', line 26 def to_h @semaphore.synchronize do @registry.get_definitions.map { |defn| [defn.id, get_bean_unsynchronized(defn.id)] }.to_h end end |