Class: Ekylibre::PluginSystem::GlobalContainer
- Inherits:
-
Object
- Object
- Ekylibre::PluginSystem::GlobalContainer
- Defined in:
- lib/ekylibre/plugin_system/global_container.rb
Overview
This class is a wrapper around RequestStore that, in addition to provide a concise way to access the container globally, ensures that a container is present if the application ask for one (nil is not a valid value)
Class Method Summary collapse
- .get ⇒ Corindon::DependencyInjection::Container
- .has? ⇒ Boolean
- .replace_with(container, &block) ⇒ Object
- .set(container) ⇒ Object
- .unset ⇒ Object
Class Method Details
.get ⇒ Corindon::DependencyInjection::Container
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ekylibre/plugin_system/global_container.rb', line 44 def get container = RequestStore['container'] if container.nil? raise StandardError.new( 'The application requires the container to be loaded to work. Please load it before calling GlobalContainer.get' ) else container end end |
.has? ⇒ Boolean
39 40 41 |
# File 'lib/ekylibre/plugin_system/global_container.rb', line 39 def has? RequestStore.exist?('container') end |
.replace_with(container, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ekylibre/plugin_system/global_container.rb', line 21 def replace_with(container, &block) prev = if has? get else nil end set(container) block.call ensure if prev.nil? unset else set(prev) end end |
.set(container) ⇒ Object
12 13 14 |
# File 'lib/ekylibre/plugin_system/global_container.rb', line 12 def set(container) RequestStore['container'] = container end |
.unset ⇒ Object
16 17 18 |
# File 'lib/ekylibre/plugin_system/global_container.rb', line 16 def unset RequestStore.delete('container') end |