Class: SmartIoC::BeanFactory
- Inherits:
-
Object
- Object
- SmartIoC::BeanFactory
- Defined in:
- lib/smart_ioc/bean_factory.rb
Overview
Instantiates beans according to their scopes
Instance Attribute Summary collapse
-
#bean_file_loader ⇒ Object
readonly
Returns the value of attribute bean_file_loader.
Instance Method Summary collapse
- #clear_scopes ⇒ Object
- #force_clear_scopes ⇒ Object
-
#get_bean(bean_name, package: nil, context: nil) ⇒ Object
Get bean from the container by it’s name, package, context.
-
#initialize(bean_definitions_storage, extra_package_contexts) ⇒ BeanFactory
constructor
A new instance of BeanFactory.
Methods included from Args
#check_arg, #check_arg_any, #not_nil
Constructor Details
#initialize(bean_definitions_storage, extra_package_contexts) ⇒ BeanFactory
8 9 10 11 12 13 14 15 |
# File 'lib/smart_ioc/bean_factory.rb', line 8 def initialize(bean_definitions_storage, extra_package_contexts) @bean_definitions_storage = bean_definitions_storage @extra_package_contexts = extra_package_contexts @bean_file_loader = SmartIoC::BeanFileLoader.new @singleton_scope = SmartIoC::Scopes::Singleton.new @prototype_scope = SmartIoC::Scopes::Prototype.new @thread_scope = SmartIoC::Scopes::Request.new end |
Instance Attribute Details
#bean_file_loader ⇒ Object (readonly)
Returns the value of attribute bean_file_loader.
6 7 8 |
# File 'lib/smart_ioc/bean_factory.rb', line 6 def bean_file_loader @bean_file_loader end |
Instance Method Details
#clear_scopes ⇒ Object
17 18 19 |
# File 'lib/smart_ioc/bean_factory.rb', line 17 def clear_scopes all_scopes.each(&:clear) end |
#force_clear_scopes ⇒ Object
21 22 23 |
# File 'lib/smart_ioc/bean_factory.rb', line 21 def force_clear_scopes all_scopes.each(&:force_clear) end |
#get_bean(bean_name, package: nil, context: nil) ⇒ Object
Get bean from the container by it’s name, package, context
32 33 34 35 36 37 38 |
# File 'lib/smart_ioc/bean_factory.rb', line 32 def get_bean(bean_name, package: nil, context: nil) check_arg(bean_name, :bean_name, Symbol) check_arg(package, :package, Symbol) if package check_arg(context, :context, Symbol) if context get_or_build_bean(bean_name, package, context) end |