Class: RubyBeans::Container
- Inherits:
-
Object
- Object
- RubyBeans::Container
- Includes:
- Singleton
- Defined in:
- lib/ruby_beans/container.rb
Instance Attribute Summary collapse
-
#dependency_loading_called ⇒ Object
Returns the value of attribute dependency_loading_called.
-
#dependent_containers ⇒ Object
Returns the value of attribute dependent_containers.
-
#dependent_containers_names ⇒ Object
Returns the value of attribute dependent_containers_names.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Container
constructor
A new instance of Container.
- #method_missing(name, *args, &block) ⇒ Object
Constructor Details
#initialize ⇒ Container
Returns a new instance of Container.
8 9 10 11 12 |
# File 'lib/ruby_beans/container.rb', line 8 def initialize @dependency_loading_called = false @dependent_containers_names = [] @dependent_containers = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby_beans/container.rb', line 26 def method_missing(name, *args, &block) name = name.to_s if dependency_loading_called && dependent_containers.empty? self.class._load_container_instances end if name.start_with?('get_') && name.end_with?('_bean') result = nil dependent_containers.each do |container| result = container.send(name) end result elsif name.end_with?('_bean') bean = RubyBeans::Cache.get name unless bean bean = self.send("get_#{name}") RubyBeans::Cache.put(name, bean) end bean else super end end |
Instance Attribute Details
#dependency_loading_called ⇒ Object
Returns the value of attribute dependency_loading_called.
6 7 8 |
# File 'lib/ruby_beans/container.rb', line 6 def dependency_loading_called @dependency_loading_called end |
#dependent_containers ⇒ Object
Returns the value of attribute dependent_containers.
6 7 8 |
# File 'lib/ruby_beans/container.rb', line 6 def dependent_containers @dependent_containers end |
#dependent_containers_names ⇒ Object
Returns the value of attribute dependent_containers_names.
6 7 8 |
# File 'lib/ruby_beans/container.rb', line 6 def dependent_containers_names @dependent_containers_names end |
Class Method Details
._load_container_instances ⇒ Object
19 20 21 22 23 |
# File 'lib/ruby_beans/container.rb', line 19 def _load_container_instances self.instance.dependent_containers_names.each do |container| self.instance.dependent_containers.push(Object.const_get(container).send(:instance)) end end |
.load_containers(*containers) ⇒ Object
14 15 16 17 |
# File 'lib/ruby_beans/container.rb', line 14 def load_containers(*containers) self.instance.dependency_loading_called = true self.instance.dependent_containers_names = containers end |