rom 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/lib/rom/commands/abstract.rb +1 -0
- data/lib/rom/commands/composite.rb +2 -0
- data/lib/rom/environment.rb +19 -2
- data/lib/rom/environment_plugins/auto_registration.rb +11 -0
- data/lib/rom/memory/dataset.rb +1 -0
- data/lib/rom/setup.rb +17 -4
- data/lib/rom/setup/finalize.rb +16 -11
- data/lib/rom/setup_dsl/setup.rb +1 -0
- data/lib/rom/version.rb +1 -1
- data/spec/integration/inline_setup_spec.rb +65 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5eaa5117425dbec0243b42bfc8e5cd2a246ee67
|
4
|
+
data.tar.gz: b4d0c29e7025e62a7e8cf8660913a1a5c5c9a65a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd50b8d43492c960dffcb3782cf0068138bacfaa05791266a8d407fe8938b5cf758360372b88be8a26f98c391fa2c857502a9547574d2e635c76ccad581f8f30
|
7
|
+
data.tar.gz: 45c454986d7b9aa01b06bc1210b75733b9daedb25a13208e7726bbe11e2000039ce0d057c94f11bd3f31adea46bfb08a8a92115abf998b58ffd79af98d1d5b09
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## v0.9.1 2015-08-21
|
2
|
+
|
3
|
+
This is a small bug-fix release which addresses a couple of issues for inline
|
4
|
+
setup DSL and multi-environments.
|
5
|
+
|
6
|
+
### Fixed
|
7
|
+
|
8
|
+
- Multi-env setup for adapters with schema-inferration support won't crash (solnic)
|
9
|
+
- Default adapter is set correctly when many adapters are configured and one is
|
10
|
+
registered under `:default` name (solnic)
|
11
|
+
- When defining a relation using inline DSL with custom dataset name the relation
|
12
|
+
name will be correctly set as `register_as` setting (solnic)
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
- When using inline-setup for env the auto_registration mechanism will be turned
|
17
|
+
on by default (solnic)
|
18
|
+
|
19
|
+
[Compare v0.9.0...v0.9.1](https://github.com/rom-rb/rom/compare/v0.9.0...v0.9.1)
|
20
|
+
|
1
21
|
## v0.9.0 2015-08-19
|
2
22
|
|
3
23
|
### Added
|
data/lib/rom/environment.rb
CHANGED
@@ -114,7 +114,16 @@ module ROM
|
|
114
114
|
# @api public
|
115
115
|
def setup(*args, &block)
|
116
116
|
config = setup_config(*args)
|
117
|
-
|
117
|
+
configured_gateways = setup_gateways(config)
|
118
|
+
|
119
|
+
default_adapter = gateways.fetch(
|
120
|
+
configured_gateways[:default], adapters.keys.first
|
121
|
+
)
|
122
|
+
|
123
|
+
@boot = Setup.new(configured_gateways,
|
124
|
+
gateway_map: gateways,
|
125
|
+
default_adapter: default_adapter
|
126
|
+
)
|
118
127
|
|
119
128
|
config.each do |name, config_args|
|
120
129
|
options = config_args.is_a?(Array) && config_args.last
|
@@ -122,13 +131,21 @@ module ROM
|
|
122
131
|
end
|
123
132
|
|
124
133
|
if block
|
134
|
+
use :auto_registration unless auto_registration?
|
125
135
|
@boot.instance_exec(&block)
|
126
|
-
|
136
|
+
finalize.container
|
127
137
|
else
|
128
138
|
@boot
|
129
139
|
end
|
130
140
|
end
|
131
141
|
|
142
|
+
# Check if auto-registration is enabled for this environment
|
143
|
+
#
|
144
|
+
# @api private
|
145
|
+
def auto_registration?
|
146
|
+
false
|
147
|
+
end
|
148
|
+
|
132
149
|
# Global relation setup DSL
|
133
150
|
#
|
134
151
|
# @example
|
@@ -6,8 +6,19 @@ module ROM
|
|
6
6
|
#
|
7
7
|
# @api public
|
8
8
|
module AutoRegistration
|
9
|
+
# Say "yes" for envs that have this plugin enabled
|
10
|
+
#
|
11
|
+
# By default it says "no" in Environment#auto_registration?
|
12
|
+
#
|
13
|
+
# @api private
|
14
|
+
def auto_registration?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
9
18
|
# @api private
|
10
19
|
def self.apply(environment, options = {})
|
20
|
+
environment.extend(AutoRegistration)
|
21
|
+
|
11
22
|
if_proc = options.fetch(:if, ->(*args) { true })
|
12
23
|
|
13
24
|
ROM::Relation.on(:inherited) do |relation|
|
data/lib/rom/memory/dataset.rb
CHANGED
data/lib/rom/setup.rb
CHANGED
@@ -18,6 +18,11 @@ module ROM
|
|
18
18
|
# @api private
|
19
19
|
attr_reader :gateways
|
20
20
|
|
21
|
+
# @attr_reader [Hash<Gateway=>Symbol>] gateway_map Environment gateway map
|
22
|
+
#
|
23
|
+
# @api private
|
24
|
+
attr_reader :gateway_map
|
25
|
+
|
21
26
|
# Deprecated accessor for gateways.
|
22
27
|
#
|
23
28
|
# @see gateways
|
@@ -50,12 +55,15 @@ module ROM
|
|
50
55
|
alias_method :env, :container
|
51
56
|
|
52
57
|
# @api private
|
53
|
-
def initialize(gateways,
|
58
|
+
def initialize(gateways, options = {})
|
54
59
|
@gateways = gateways
|
55
|
-
|
60
|
+
|
61
|
+
@gateway_map = options.fetch(:gateway_map, {})
|
62
|
+
@default_adapter = options.fetch(:default_adapter, nil)
|
63
|
+
|
56
64
|
@relation_classes = []
|
57
|
-
@mapper_classes = []
|
58
65
|
@command_classes = []
|
66
|
+
@mapper_classes = []
|
59
67
|
@container = nil
|
60
68
|
end
|
61
69
|
|
@@ -76,7 +84,12 @@ module ROM
|
|
76
84
|
end
|
77
85
|
|
78
86
|
finalize = Finalize.new(
|
79
|
-
gateways
|
87
|
+
gateways: gateways,
|
88
|
+
gateway_map: gateway_map,
|
89
|
+
relation_classes: relation_classes,
|
90
|
+
command_classes: command_classes,
|
91
|
+
mappers: mapper_classes,
|
92
|
+
config: config.freeze
|
80
93
|
)
|
81
94
|
|
82
95
|
@container = finalize.run!
|
data/lib/rom/setup/finalize.rb
CHANGED
@@ -16,18 +16,23 @@ module ROM
|
|
16
16
|
#
|
17
17
|
# @private
|
18
18
|
class Finalize
|
19
|
-
attr_reader :gateways, :repo_adapter, :datasets,
|
20
|
-
:relation_classes, :mapper_classes, :
|
19
|
+
attr_reader :gateways, :repo_adapter, :datasets, :gateway_map,
|
20
|
+
:relation_classes, :mapper_classes, :mapper_objects, :command_classes, :config
|
21
21
|
|
22
22
|
# @api private
|
23
|
-
def initialize(
|
24
|
-
@gateways = gateways
|
25
|
-
@
|
26
|
-
|
23
|
+
def initialize(options)
|
24
|
+
@gateways = options.fetch(:gateways)
|
25
|
+
@gateway_map = options.fetch(:gateway_map)
|
26
|
+
|
27
|
+
@relation_classes = options.fetch(:relation_classes)
|
28
|
+
@command_classes = options.fetch(:command_classes)
|
29
|
+
|
30
|
+
mappers = options.fetch(:mappers, [])
|
27
31
|
@mapper_classes = mappers.select { |mapper| mapper.is_a?(Class) }
|
28
|
-
@
|
29
|
-
|
30
|
-
@config = config
|
32
|
+
@mapper_objects = (mappers - @mapper_classes).reduce(:merge) || {}
|
33
|
+
|
34
|
+
@config = options.fetch(:config)
|
35
|
+
|
31
36
|
initialize_datasets
|
32
37
|
end
|
33
38
|
|
@@ -37,7 +42,7 @@ module ROM
|
|
37
42
|
#
|
38
43
|
# @api private
|
39
44
|
def adapter_for(gateway)
|
40
|
-
@
|
45
|
+
@gateway_map.fetch(gateways[gateway])
|
41
46
|
end
|
42
47
|
|
43
48
|
# Run the finalization process
|
@@ -90,7 +95,7 @@ module ROM
|
|
90
95
|
h[relation] = MapperRegistry.new(mappers)
|
91
96
|
}
|
92
97
|
|
93
|
-
|
98
|
+
mapper_objects.each do |relation, mappers|
|
94
99
|
if registry_hash.key?(relation)
|
95
100
|
mappers.each { |name, mapper| registry[name] = mapper }
|
96
101
|
else
|
data/lib/rom/setup_dsl/setup.rb
CHANGED
data/lib/rom/version.rb
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rom/memory'
|
3
|
+
|
4
|
+
RSpec.describe 'Inline setup' do
|
5
|
+
before do
|
6
|
+
module Test
|
7
|
+
module Dummy
|
8
|
+
class Gateway < ROM::Memory::Gateway
|
9
|
+
def schema
|
10
|
+
[:users, :tasks]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Relation < ROM::Relation
|
15
|
+
adapter :dummy
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
ROM.register_adapter :dummy, Test::Dummy
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'using global env' do
|
24
|
+
it 'auto-registers components' do
|
25
|
+
rom = ROM.setup(:dummy) do
|
26
|
+
relation(:users)
|
27
|
+
end
|
28
|
+
|
29
|
+
users = rom.relation(:users)
|
30
|
+
|
31
|
+
expect(users).to be_kind_of(Test::Dummy::Relation)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'using local env' do
|
36
|
+
it 'auto-registers components' do
|
37
|
+
env = ROM::Environment.new
|
38
|
+
|
39
|
+
rom = env.setup(:dummy) do
|
40
|
+
relation(:users)
|
41
|
+
end
|
42
|
+
|
43
|
+
users = rom.relation(:users)
|
44
|
+
|
45
|
+
expect(users).to be_kind_of(Test::Dummy::Relation)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'defining a relation with custom dataset name' do
|
50
|
+
it 'registers under provided name and uses custom dataset' do
|
51
|
+
env = ROM::Environment.new
|
52
|
+
|
53
|
+
rom = env.setup(:dummy) do
|
54
|
+
relation(:super_users) do
|
55
|
+
dataset :users
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
users = rom.relation(:super_users)
|
60
|
+
|
61
|
+
expect(users).to be_kind_of(Test::Dummy::Relation)
|
62
|
+
expect(users.dataset).to be(rom.gateways[:default].dataset(:users))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: transproc
|
@@ -204,6 +204,7 @@ files:
|
|
204
204
|
- spec/integration/commands/error_handling_spec.rb
|
205
205
|
- spec/integration/commands/graph_spec.rb
|
206
206
|
- spec/integration/commands/update_spec.rb
|
207
|
+
- spec/integration/inline_setup_spec.rb
|
207
208
|
- spec/integration/mappers/combine_spec.rb
|
208
209
|
- spec/integration/mappers/deep_embedded_spec.rb
|
209
210
|
- spec/integration/mappers/definition_dsl_spec.rb
|