Class: ROM::Environment
- Inherits:
-
Object
- Object
- ROM::Environment
- Defined in:
- lib/rom/session.rb,
lib/rom/environment.rb,
lib/rom/environment/builder.rb
Overview
The environment configures repositories and loads schema with relations
Defined Under Namespace
Classes: Builder
Instance Attribute Summary collapse
-
#mappers ⇒ Hash
readonly
Return mapper registry.
- #relations ⇒ Object readonly private
- #repositories ⇒ Object readonly private
-
#schema ⇒ Schema
readonly
Return schema registry.
Class Method Summary collapse
-
.setup(config, &block) ⇒ Environment::Builder
Setup ROM environment.
Instance Method Summary collapse
-
#[](name) ⇒ Relation
Return registered relation.
-
#initialize(repositories, schema, relations, mappers) ⇒ Environment
constructor
private
A new instance of Environment.
-
#repository(name) ⇒ Repository
The repository with the given
name
. -
#session(&block) ⇒ Object
Start a new session for this environment.
Constructor Details
#initialize(repositories, schema, relations, mappers) ⇒ Environment
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 Environment.
28 29 30 31 32 33 |
# File 'lib/rom/environment.rb', line 28 def initialize(repositories, schema, relations, mappers) @repositories = repositories @schema = schema @relations = relations @mappers = mappers end |
Instance Attribute Details
#mappers ⇒ Hash (readonly)
Return mapper registry
25 26 27 |
# File 'lib/rom/environment.rb', line 25 def mappers @mappers end |
#relations ⇒ 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.
11 12 13 |
# File 'lib/rom/environment.rb', line 11 def relations @relations end |
#repositories ⇒ 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.
11 12 13 |
# File 'lib/rom/environment.rb', line 11 def repositories @repositories end |
#schema ⇒ Schema (readonly)
Return schema registry
18 19 20 |
# File 'lib/rom/environment.rb', line 18 def schema @schema end |
Class Method Details
.setup(config, &block) ⇒ Environment::Builder
Setup ROM environment
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rom/environment.rb', line 68 def self.setup(config, &block) builder = Builder.call(config) if block builder.instance_eval(&block) builder.finalize else builder end end |
Instance Method Details
#[](name) ⇒ Relation
Return registered relation
90 91 92 |
# File 'lib/rom/environment.rb', line 90 def [](name) relations[name] end |
#repository(name) ⇒ Repository
The repository with the given name
99 100 101 |
# File 'lib/rom/environment.rb', line 99 def repository(name) repositories[name] end |
#session(&block) ⇒ Object
Start a new session for this environment
31 32 33 |
# File 'lib/rom/session.rb', line 31 def session(&block) Session.start(self, &block) end |