Class: ROM::Container
- Inherits:
-
Object
- Object
- ROM::Container
- Includes:
- Dry::Core::Container::Mixin
- Defined in:
- lib/rom/container.rb
Overview
ROM container is an isolated environment with no global state where all components are registered. Container objects provide access to your relations, commands and mappers. ROM containers are usually configured and handled via framework integrations, although it is easy to use them standalone.
There are 3 types of container setup:
-
Setup DSL - a simple block-based configuration which allows configuring all components and gives you back a container instance. This type is suitable for small scripts, or in some cases rake tasks
-
Explicit setup - this type requires creating a configuration object, registering component classes (ie relation classes) and passing the config to container builder function. This type is suitable when your environment is not typical and you need full control over component registration
-
Explicit setup with auto-registration - same as explicit setup but allows you to configure auto-registration mechanism which will register component classes for you, based on dir/file naming conventions. This is the most common type of setup that’s used by framework integrations
Instance Attribute Summary collapse
- #cache ⇒ Object readonly private
Class Method Summary collapse
Instance Method Summary collapse
-
#commands ⇒ Hash<Symbol=>CommandRegistry]
Return command registry.
-
#disconnect ⇒ Hash<Symbol=>Gateway>
Disconnect all gateways.
-
#gateways ⇒ Hash<Symbol=>Gateway>
Return registered gateways.
-
#initialize ⇒ Container
constructor
private
A new instance of Container.
-
#mappers ⇒ Hash<Symbol=>MapperRegistry]
Return mapper registry for all relations.
-
#relations ⇒ RelationRegistry
Return relation registry.
Constructor Details
#initialize ⇒ Container
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Container.
117 118 119 120 121 |
# File 'lib/rom/container.rb', line 117 def initialize super @cache = Cache.new end |
Instance Attribute Details
#cache ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
114 115 116 |
# File 'lib/rom/container.rb', line 114 def cache @cache end |
Class Method Details
.new(gateways, relations, mappers, commands) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
104 105 106 107 108 109 110 111 |
# File 'lib/rom/container.rb', line 104 def self.new(gateways, relations, mappers, commands) super().tap do |container| container.register(:gateways, gateways) container.register(:mappers, mappers) container.register(:commands, commands) container.register(:relations, relations) end end |
Instance Method Details
#commands ⇒ Hash<Symbol=>CommandRegistry]
Return command registry
149 |
# File 'lib/rom/container.rb', line 149 def commands = self[:commands] |
#disconnect ⇒ Hash<Symbol=>Gateway>
Disconnect all gateways
161 |
# File 'lib/rom/container.rb', line 161 def disconnect = gateways.each_value(&:disconnect) |
#gateways ⇒ Hash<Symbol=>Gateway>
Return registered gateways
128 |
# File 'lib/rom/container.rb', line 128 def gateways = self[:gateways] |
#mappers ⇒ Hash<Symbol=>MapperRegistry]
Return mapper registry for all relations
135 |
# File 'lib/rom/container.rb', line 135 def mappers = self[:mappers] |
#relations ⇒ RelationRegistry
Return relation registry
142 |
# File 'lib/rom/container.rb', line 142 def relations = self[:relations] |