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
Class Method Summary collapse
- .new(configuration) ⇒ Object private
Instance Method Summary collapse
-
#commands ⇒ Hash<Symbol=>CommandRegistry]
Return command registry.
-
#configuration ⇒ Setup::Configuration
Return runtime configuration with component registries.
-
#disconnect ⇒ Hash<Symbol=>Gateway>
Disconnect all gateways.
-
#gateways ⇒ Hash<Symbol=>Gateway>
Return registered gateways.
-
#mappers ⇒ Hash<Symbol=>MapperRegistry]
Return mapper registry for all relations.
-
#relations ⇒ RelationRegistry
Return relation registry.
-
#schemas ⇒ RelationRegistry
Return relation registry.
Class Method Details
.new(configuration) ⇒ 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.
102 103 104 105 106 107 108 109 110 |
# File 'lib/rom/container.rb', line 102 def self.new(configuration) super().tap do |container| container.register(:configuration, memoize: true) do Setup::Configuration.new( configuration: configuration, container: container ) end end end |
Instance Method Details
#commands ⇒ Hash<Symbol=>CommandRegistry]
Return command registry
162 163 164 |
# File 'lib/rom/container.rb', line 162 def commands configuration.commands end |
#configuration ⇒ Setup::Configuration
Return runtime configuration with component registries
117 118 119 |
# File 'lib/rom/container.rb', line 117 def configuration self[:configuration] end |
#disconnect ⇒ Hash<Symbol=>Gateway>
Disconnect all gateways
176 177 178 |
# File 'lib/rom/container.rb', line 176 def disconnect gateways.each_value(&:disconnect) end |
#gateways ⇒ Hash<Symbol=>Gateway>
Return registered gateways
126 127 128 |
# File 'lib/rom/container.rb', line 126 def gateways configuration.gateways end |
#mappers ⇒ Hash<Symbol=>MapperRegistry]
Return mapper registry for all relations
153 154 155 |
# File 'lib/rom/container.rb', line 153 def mappers configuration.mappers end |
#relations ⇒ RelationRegistry
Return relation registry
144 145 146 |
# File 'lib/rom/container.rb', line 144 def relations configuration.relations end |
#schemas ⇒ RelationRegistry
Return relation registry
135 136 137 |
# File 'lib/rom/container.rb', line 135 def schemas configuration.schemas end |