Class: ROM::Environment
- Inherits:
-
Object
- Object
- ROM::Environment
- Defined in:
- lib/rom/environment.rb
Overview
The environment configures repositories and loads schema with relations
Class Method Summary collapse
-
.build(repositories, registry = {}) ⇒ Environment
private
Build a new environment.
-
.setup(config) ⇒ Environment
Build an environment instance from a repository config hash.
Instance Method Summary collapse
-
#[](name) ⇒ Relation
Return registered relation.
-
#[]=(name, relation) ⇒ Environment
private
Register a rom relation.
-
#mapping(&block) ⇒ Mapping
Define mapping for relations.
-
#repository(name) ⇒ Repository
The repository with the given
name
. -
#schema(&block) ⇒ Schema
Build a relation schema for this environment.
Class Method Details
.build(repositories, registry = {}) ⇒ 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.
Build a new environment
43 44 45 |
# File 'lib/rom/environment.rb', line 43 def self.build(repositories, registry = {}) new(repositories, registry) end |
.setup(config) ⇒ Environment
Build an environment instance from a repository config hash
24 25 26 27 28 29 30 31 32 |
# File 'lib/rom/environment.rb', line 24 def self.setup(config) return config if config.kind_of?(self) repositories = config.each_with_object({}) { |(name, uri), hash| hash[name.to_sym] = Repository.build(name, Addressable::URI.parse(uri)) } build(repositories) end |
Instance Method Details
#[](name) ⇒ Relation
Return registered relation
110 111 112 |
# File 'lib/rom/environment.rb', line 110 def [](name) registry[name] end |
#[]=(name, relation) ⇒ 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.
Register a rom relation
119 120 121 |
# File 'lib/rom/environment.rb', line 119 def []=(name, relation) registry[name] = relation end |
#mapping(&block) ⇒ Mapping
Define mapping for relations
95 96 97 |
# File 'lib/rom/environment.rb', line 95 def mapping(&block) Mapping.build(self, schema, &block) end |
#repository(name) ⇒ Repository
The repository with the given name
128 129 130 |
# File 'lib/rom/environment.rb', line 128 def repository(name) repositories[name] end |