rom 0.6.0.beta3 → 0.6.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/CHANGELOG.md +2 -1
- data/Gemfile +1 -1
- data/lib/rom.rb +0 -2
- data/lib/rom/commands/abstract.rb +1 -1
- data/lib/rom/env.rb +9 -7
- data/lib/rom/memory/storage.rb +6 -1
- data/lib/rom/relation.rb +14 -134
- data/lib/rom/relation/class_interface.rb +180 -0
- data/lib/rom/relation/lazy.rb +1 -1
- data/lib/rom/relation/registry_reader.rb +1 -1
- data/lib/rom/setup/finalize.rb +1 -21
- data/lib/rom/version.rb +1 -1
- data/rakelib/benchmark.rake +3 -1
- data/rom.gemspec +2 -2
- data/spec/integration/mappers/deep_embedded_spec.rb +1 -1
- data/spec/integration/mappers/definition_dsl_spec.rb +8 -6
- data/spec/integration/mappers/embedded_spec.rb +2 -6
- data/spec/integration/mappers/group_spec.rb +4 -4
- data/spec/integration/mappers/prefixing_attributes_spec.rb +1 -1
- data/spec/integration/mappers/renaming_attributes_spec.rb +5 -3
- data/spec/integration/mappers/symbolizing_attributes_spec.rb +2 -2
- data/spec/integration/mappers/wrap_spec.rb +4 -4
- data/spec/integration/multi_repo_spec.rb +5 -1
- data/spec/integration/relations/reading_spec.rb +6 -14
- data/spec/integration/setup_spec.rb +3 -3
- data/spec/unit/rom/env_spec.rb +1 -1
- data/spec/unit/rom/relation/lazy_spec.rb +16 -4
- data/spec/unit/rom/setup_spec.rb +2 -2
- metadata +9 -4
- data/lib/rom/reader.rb +0 -174
- data/spec/unit/rom/reader_spec.rb +0 -146
data/lib/rom/relation/lazy.rb
CHANGED
data/lib/rom/setup/finalize.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rom/relation'
|
2
2
|
require 'rom/mapper'
|
3
|
-
require 'rom/reader'
|
4
3
|
require 'rom/command'
|
5
4
|
|
6
5
|
require 'rom/support/registry'
|
@@ -52,9 +51,8 @@ module ROM
|
|
52
51
|
relations = load_relations
|
53
52
|
mappers = load_mappers
|
54
53
|
commands = load_commands(relations)
|
55
|
-
readers = load_readers(relations, mappers)
|
56
54
|
|
57
|
-
Env.new(repositories, relations, mappers, commands
|
55
|
+
Env.new(repositories, relations, mappers, commands)
|
58
56
|
end
|
59
57
|
|
60
58
|
private
|
@@ -91,24 +89,6 @@ module ROM
|
|
91
89
|
Registry.new(registry_hash)
|
92
90
|
end
|
93
91
|
|
94
|
-
# Build entire reader and mapper registries
|
95
|
-
#
|
96
|
-
# @api private
|
97
|
-
def load_readers(relations, mappers)
|
98
|
-
readers = {}
|
99
|
-
|
100
|
-
mappers.each do |name, rel_mappers|
|
101
|
-
next unless rel_mappers.key?(name)
|
102
|
-
|
103
|
-
relation = relations[name]
|
104
|
-
methods = relation.exposed_relations
|
105
|
-
|
106
|
-
readers[name] = Reader.build(name, relation, rel_mappers, methods)
|
107
|
-
end
|
108
|
-
|
109
|
-
ReaderRegistry.new(readers)
|
110
|
-
end
|
111
|
-
|
112
92
|
# Build entire command registries
|
113
93
|
#
|
114
94
|
# This includes both classes created via DSL and explicit definitions
|
data/lib/rom/version.rb
CHANGED
data/rakelib/benchmark.rake
CHANGED
data/rom.gemspec
CHANGED
@@ -16,8 +16,8 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.license = 'MIT'
|
17
17
|
gem.required_ruby_version = '~> 2.0'
|
18
18
|
|
19
|
-
gem.add_runtime_dependency 'transproc',
|
20
|
-
gem.add_runtime_dependency 'equalizer',
|
19
|
+
gem.add_runtime_dependency 'transproc', '~> 0.1', '>= 0.1.2'
|
20
|
+
gem.add_runtime_dependency 'equalizer', '~> 0.0', '>= 0.0.9'
|
21
21
|
|
22
22
|
gem.add_development_dependency 'rake', '~> 10.3'
|
23
23
|
gem.add_development_dependency 'rspec-core', '~> 3.2'
|
@@ -14,13 +14,15 @@ describe 'Mapper definition DSL' do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe 'default PORO mapper' do
|
17
|
-
subject(:mapper) { rom.
|
17
|
+
subject(:mapper) { rom.mappers.users.entity }
|
18
18
|
|
19
19
|
before do
|
20
20
|
setup.mappers do
|
21
21
|
define(:users) do
|
22
22
|
model name: 'Test::User'
|
23
23
|
|
24
|
+
register_as :entity
|
25
|
+
|
24
26
|
attribute :name
|
25
27
|
attribute :email
|
26
28
|
end
|
@@ -38,7 +40,7 @@ describe 'Mapper definition DSL' do
|
|
38
40
|
|
39
41
|
describe 'excluding attributes' do
|
40
42
|
context 'by setting :inherit_header to false' do
|
41
|
-
subject(:mapper) { rom.
|
43
|
+
subject(:mapper) { rom.mappers.users.email_index }
|
42
44
|
|
43
45
|
before do
|
44
46
|
setup.mappers do
|
@@ -63,7 +65,7 @@ describe 'Mapper definition DSL' do
|
|
63
65
|
end
|
64
66
|
|
65
67
|
describe 'virtual relation mapper' do
|
66
|
-
subject(:mapper) { rom.
|
68
|
+
subject(:mapper) { rom.mappers.users.email_index }
|
67
69
|
|
68
70
|
before do
|
69
71
|
setup.mappers do
|
@@ -124,7 +126,7 @@ describe 'Mapper definition DSL' do
|
|
124
126
|
|
125
127
|
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
126
128
|
|
127
|
-
jane = rom.
|
129
|
+
jane = rom.relation(:tasks).with_user.as(:with_user).to_a.last
|
128
130
|
|
129
131
|
expect(jane).to eql(
|
130
132
|
Test::TaskWithUser.new(
|
@@ -153,7 +155,7 @@ describe 'Mapper definition DSL' do
|
|
153
155
|
|
154
156
|
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
155
157
|
|
156
|
-
jane = rom.
|
158
|
+
jane = rom.relation(:tasks).with_user.as(:with_user).to_a.last
|
157
159
|
|
158
160
|
expect(jane).to eql(
|
159
161
|
Test::TaskWithUser.new(
|
@@ -184,7 +186,7 @@ describe 'Mapper definition DSL' do
|
|
184
186
|
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
185
187
|
Test::User.send(:include, Equalizer.new(:email))
|
186
188
|
|
187
|
-
jane = rom.
|
189
|
+
jane = rom.relation(:tasks).with_user.as(:with_user).to_a.last
|
188
190
|
|
189
191
|
expect(jane).to eql(
|
190
192
|
Test::TaskWithUser.new(
|
@@ -25,9 +25,7 @@ describe 'Mappers / embedded' do
|
|
25
25
|
'tasks' => [{ 'title' => 'Task One' }, { 'title' => 'Task Two' }]
|
26
26
|
}
|
27
27
|
|
28
|
-
jane = rom.
|
29
|
-
|
30
|
-
expect(rom.read(:users).mapper.header.map(&:name)).to eql([:name, :tasks])
|
28
|
+
jane = rom.relation(:users).map_with(:users).first
|
31
29
|
|
32
30
|
expect(jane.name).to eql('Jane')
|
33
31
|
expect(jane.tasks).to eql([{ title: 'Task One' }, { title: 'Task Two' }])
|
@@ -55,9 +53,7 @@ describe 'Mappers / embedded' do
|
|
55
53
|
'address' => { 'street' => 'Somewhere 1', 'city' => 'NYC' }
|
56
54
|
}
|
57
55
|
|
58
|
-
jane = rom.
|
59
|
-
|
60
|
-
expect(rom.read(:users).mapper.header.map(&:name)).to eql([:name, :address])
|
56
|
+
jane = rom.relation(:users).as(:users).first
|
61
57
|
|
62
58
|
Test::Address.send(:include, Equalizer.new(:street, :city))
|
63
59
|
|
@@ -45,7 +45,7 @@ describe 'Mapper definition DSL' do
|
|
45
45
|
|
46
46
|
Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
|
47
47
|
|
48
|
-
jane = rom.
|
48
|
+
jane = rom.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
|
49
49
|
|
50
50
|
expect(jane).to eql(
|
51
51
|
Test::UserWithTasks.new(
|
@@ -75,7 +75,7 @@ describe 'Mapper definition DSL' do
|
|
75
75
|
|
76
76
|
Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
|
77
77
|
|
78
|
-
jane = rom.
|
78
|
+
jane = rom.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
|
79
79
|
|
80
80
|
expect(jane).to eql(
|
81
81
|
Test::UserWithTasks.new(
|
@@ -108,7 +108,7 @@ describe 'Mapper definition DSL' do
|
|
108
108
|
Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
|
109
109
|
Test::Task.send(:include, Equalizer.new(:title, :priority))
|
110
110
|
|
111
|
-
jane = rom.
|
111
|
+
jane = rom.relation(:users).with_tasks.map_with(:with_tasks).to_a.last
|
112
112
|
|
113
113
|
expect(jane).to eql(
|
114
114
|
Test::UserWithTasks.new(
|
@@ -148,7 +148,7 @@ describe 'Mapper definition DSL' do
|
|
148
148
|
Test::TaskUser.send(:include, Equalizer.new(:name, :contacts))
|
149
149
|
Test::Contact.send(:include, Equalizer.new(:email))
|
150
150
|
|
151
|
-
task = rom.
|
151
|
+
task = rom.relation(:tasks).with_users.map_with(:with_users).first
|
152
152
|
|
153
153
|
expect(task).to eql(
|
154
154
|
Test::TaskWithUsers.new(title: 'be nice', priority: 1, users: [
|
@@ -30,7 +30,7 @@ describe 'Mappers / Prefixing attributes' do
|
|
30
30
|
user_email: 'jane@doe.org'
|
31
31
|
}
|
32
32
|
|
33
|
-
jane = rom.
|
33
|
+
jane = rom.relation(:users).as(:users).first
|
34
34
|
|
35
35
|
expect(jane).to eql(Test::User.new(id: 123, name: 'Jane', email: 'jane@doe.org'))
|
36
36
|
end
|
@@ -34,7 +34,7 @@ describe 'Mappers / Renaming attributes' do
|
|
34
34
|
|
35
35
|
rom.relations.users << { _id: 123, user_name: 'Jane' }
|
36
36
|
|
37
|
-
jane = rom.
|
37
|
+
jane = rom.relation(:users).as(:users).first
|
38
38
|
|
39
39
|
expect(jane).to eql(Test::User.new(id: 123, name: 'Jane'))
|
40
40
|
end
|
@@ -66,10 +66,11 @@ describe 'Mappers / Renaming attributes' do
|
|
66
66
|
Test::UserWithAddress.send(:include, Equalizer.new(:id, :name, :address))
|
67
67
|
|
68
68
|
rom.relations.users << { _id: 123, user_name: 'Jane' }
|
69
|
+
|
69
70
|
rom.relations.addresses <<
|
70
71
|
{ _id: 123, address_id: 321, address_street: 'Street 1' }
|
71
72
|
|
72
|
-
jane = rom.
|
73
|
+
jane = rom.relation(:users).with_address.as(:with_address).first
|
73
74
|
|
74
75
|
expect(jane).to eql(
|
75
76
|
Test::UserWithAddress.new(id: 123, name: 'Jane',
|
@@ -104,12 +105,13 @@ describe 'Mappers / Renaming attributes' do
|
|
104
105
|
Test::UserWithAddresses.send(:include, Equalizer.new(:id, :name, :addresses))
|
105
106
|
|
106
107
|
rom.relations.users << { _id: 123, user_name: 'Jane' }
|
108
|
+
|
107
109
|
rom.relations.addresses <<
|
108
110
|
{ _id: 123, address_id: 321, address_street: 'Street 1' }
|
109
111
|
rom.relations.addresses <<
|
110
112
|
{ _id: 123, address_id: 654, address_street: 'Street 2' }
|
111
113
|
|
112
|
-
jane = rom.
|
114
|
+
jane = rom.relation(:users).with_addresses.as(:with_addresses).first
|
113
115
|
|
114
116
|
expect(jane).to eql(
|
115
117
|
Test::UserWithAddresses.new(
|
@@ -36,7 +36,7 @@ describe 'Mappers / Symbolizing atributes' do
|
|
36
36
|
'email' => 'jane@doe.org'
|
37
37
|
}
|
38
38
|
|
39
|
-
jane = rom.
|
39
|
+
jane = rom.relation(:users).as(:users).first
|
40
40
|
|
41
41
|
expect(jane).to eql(
|
42
42
|
id: 123, details: { name: 'Jane' }, contact: { email: 'jane@doe.org' }
|
@@ -64,7 +64,7 @@ describe 'Mappers / Symbolizing atributes' do
|
|
64
64
|
'task_description' => 'It is a task'
|
65
65
|
}
|
66
66
|
|
67
|
-
task = rom.
|
67
|
+
task = rom.relation(:tasks).as(:tasks).first
|
68
68
|
|
69
69
|
expect(task).to eql(
|
70
70
|
title: 'Task One',
|
@@ -41,7 +41,7 @@ describe 'Mapper definition DSL' do
|
|
41
41
|
|
42
42
|
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
43
43
|
|
44
|
-
jane = rom.
|
44
|
+
jane = rom.relation(:tasks).with_user.as(:with_user).to_a.last
|
45
45
|
|
46
46
|
expect(jane).to eql(
|
47
47
|
Test::TaskWithUser.new(
|
@@ -70,7 +70,7 @@ describe 'Mapper definition DSL' do
|
|
70
70
|
|
71
71
|
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
72
72
|
|
73
|
-
jane = rom.
|
73
|
+
jane = rom.relation(:tasks).with_user.as(:with_user).to_a.last
|
74
74
|
|
75
75
|
expect(jane).to eql(
|
76
76
|
Test::TaskWithUser.new(
|
@@ -107,7 +107,7 @@ describe 'Mapper definition DSL' do
|
|
107
107
|
Test::TaskUser.send(:include, Equalizer.new(:name, :contact))
|
108
108
|
Test::Contact.send(:include, Equalizer.new(:email))
|
109
109
|
|
110
|
-
jane = rom.
|
110
|
+
jane = rom.relation(:tasks).with_user.as(:with_user).to_a.last
|
111
111
|
|
112
112
|
expect(jane).to eql(
|
113
113
|
Test::TaskWithUser.new(
|
@@ -140,7 +140,7 @@ describe 'Mapper definition DSL' do
|
|
140
140
|
Test::TaskWithUser.send(:include, Equalizer.new(:title, :priority, :user))
|
141
141
|
Test::User.send(:include, Equalizer.new(:email))
|
142
142
|
|
143
|
-
jane = rom.
|
143
|
+
jane = rom.relation(:tasks).with_user.as(:with_user).to_a.last
|
144
144
|
|
145
145
|
expect(jane).to eql(
|
146
146
|
Test::TaskWithUser.new(
|
@@ -35,7 +35,11 @@ describe 'Using in-memory repositories for cross-repo access' do
|
|
35
35
|
repositories[:right][:tasks] << { user_id: 1, title: 'Have fun' }
|
36
36
|
repositories[:right][:tasks] << { user_id: 2, title: 'Have fun' }
|
37
37
|
|
38
|
-
|
38
|
+
user_and_tasks = rom.relation(:users_and_tasks)
|
39
|
+
.by_user('Jane')
|
40
|
+
.as(:users_and_tasks)
|
41
|
+
|
42
|
+
expect(user_and_tasks).to match_array([
|
39
43
|
{ user_id: 2, name: 'Jane', tasks: [{ title: 'Have fun' }] }
|
40
44
|
])
|
41
45
|
end
|
@@ -27,7 +27,7 @@ describe 'Reading relations' do
|
|
27
27
|
|
28
28
|
rom = setup.finalize
|
29
29
|
|
30
|
-
users = rom.
|
30
|
+
users = rom.relation(:users).sorted.by_name('Jane').as(:users)
|
31
31
|
user = users.first
|
32
32
|
|
33
33
|
expect(user).to be_an_instance_of(Test::User)
|
@@ -68,18 +68,13 @@ describe 'Reading relations' do
|
|
68
68
|
Test::User.send(:include, Equalizer.new(:name, :email))
|
69
69
|
Test::UserWithTasks.send(:include, Equalizer.new(:name, :email, :tasks))
|
70
70
|
|
71
|
-
|
72
|
-
expect(keys).to eql([:name, :email, :tasks])
|
73
|
-
|
74
|
-
user = rom.read(:users).sorted.first
|
71
|
+
user = rom.relation(:users).sorted.as(:users).first
|
75
72
|
|
76
73
|
expect(user).to eql(
|
77
74
|
Test::User.new(name: "Jane", email: "jane@doe.org")
|
78
75
|
)
|
79
76
|
|
80
|
-
|
81
|
-
|
82
|
-
user = rom.read(:users).with_tasks.sorted.first
|
77
|
+
user = rom.relation(:users).with_tasks.sorted.as(:with_tasks).first
|
83
78
|
|
84
79
|
expect(user).to eql(
|
85
80
|
Test::UserWithTasks.new(
|
@@ -122,10 +117,7 @@ describe 'Reading relations' do
|
|
122
117
|
Test::User.send(:include, Equalizer.new(:name, :email))
|
123
118
|
Test::UserWithTask.send(:include, Equalizer.new(:name, :email, :task))
|
124
119
|
|
125
|
-
|
126
|
-
expect(keys).to eql([:name, :email, :task])
|
127
|
-
|
128
|
-
user = rom.read(:users).sorted.with_task.first
|
120
|
+
user = rom.relation(:users).sorted.with_task.as(:with_task).first
|
129
121
|
|
130
122
|
expect(user).to eql(
|
131
123
|
Test::UserWithTask.new(name: "Jane", email: "jane@doe.org",
|
@@ -146,7 +138,7 @@ describe 'Reading relations' do
|
|
146
138
|
|
147
139
|
rom = setup.finalize
|
148
140
|
|
149
|
-
user = rom.
|
141
|
+
user = rom.relation(:users).by_name("Jane").as(:users).first
|
150
142
|
|
151
143
|
expect(user).to eql(name: "Jane", email: "jane@doe.org")
|
152
144
|
end
|
@@ -167,7 +159,7 @@ describe 'Reading relations' do
|
|
167
159
|
end
|
168
160
|
|
169
161
|
rom = setup.finalize
|
170
|
-
user = rom.
|
162
|
+
user = rom.relation(:users).map_with(:prefixer).first
|
171
163
|
|
172
164
|
expect(user).to eql(user_name: 'Joe', user_email: "joe@doe.org")
|
173
165
|
end
|
@@ -44,7 +44,7 @@ describe 'Setting up ROM' do
|
|
44
44
|
rom = setup.finalize
|
45
45
|
|
46
46
|
expect(rom.relations).to eql(ROM::RelationRegistry.new)
|
47
|
-
expect(rom.
|
47
|
+
expect(rom.mappers).to eql(ROM::Registry.new)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -110,7 +110,7 @@ describe 'Setting up ROM' do
|
|
110
110
|
|
111
111
|
rom.commands.users.create.call(name: 'Jane')
|
112
112
|
|
113
|
-
expect(rom.
|
113
|
+
expect(rom.relation(:users).by_name('Jane').as(:users).to_a)
|
114
114
|
.to eql([Test::User.new(name: 'Jane')])
|
115
115
|
end
|
116
116
|
end
|
@@ -146,7 +146,7 @@ describe 'Setting up ROM' do
|
|
146
146
|
|
147
147
|
rom.command(:users).create.call(name: 'Jane')
|
148
148
|
|
149
|
-
expect(rom.
|
149
|
+
expect(rom.relation(:users).by_name('Jane').as(:users).to_a)
|
150
150
|
.to eql([Test::User.new(name: 'Jane')])
|
151
151
|
end
|
152
152
|
end
|
data/spec/unit/rom/env_spec.rb
CHANGED
@@ -8,14 +8,14 @@ describe ROM::Relation::Lazy do
|
|
8
8
|
|
9
9
|
before do
|
10
10
|
setup.relation(:users) do
|
11
|
-
def repository
|
12
|
-
:default
|
13
|
-
end
|
14
|
-
|
15
11
|
def by_name(name)
|
16
12
|
restrict(name: name)
|
17
13
|
end
|
18
14
|
|
15
|
+
def by_name_sorted(name, order_by = :name)
|
16
|
+
by_name(name).order(order_by)
|
17
|
+
end
|
18
|
+
|
19
19
|
def by_email(email)
|
20
20
|
restrict(name: email)
|
21
21
|
end
|
@@ -129,6 +129,10 @@ describe ROM::Relation::Lazy do
|
|
129
129
|
ArgumentError, 'ROM::Relation[Users]#by_name arity is 1 (0 args given)'
|
130
130
|
)
|
131
131
|
end
|
132
|
+
|
133
|
+
it 'does not raise when relation is curried and arity matches' do
|
134
|
+
expect { users.by_name_sorted('Joe').first }.to_not raise_error
|
135
|
+
end
|
132
136
|
end
|
133
137
|
|
134
138
|
describe '#each' do
|
@@ -153,6 +157,10 @@ describe ROM::Relation::Lazy do
|
|
153
157
|
ArgumentError, 'ROM::Relation[Users]#by_name arity is 1 (0 args given)'
|
154
158
|
)
|
155
159
|
end
|
160
|
+
|
161
|
+
it 'does not raise when relation is curried and arity matches' do
|
162
|
+
expect { users.by_name_sorted('Jane').first }.to_not raise_error
|
163
|
+
end
|
156
164
|
end
|
157
165
|
|
158
166
|
describe '#to_ary' do
|
@@ -168,6 +176,10 @@ describe ROM::Relation::Lazy do
|
|
168
176
|
ArgumentError, 'ROM::Relation[Users]#by_name arity is 1 (0 args given)'
|
169
177
|
)
|
170
178
|
end
|
179
|
+
|
180
|
+
it 'does not raise when relation is curried and arity matches' do
|
181
|
+
expect { users.by_name_sorted('Jane').first }.to_not raise_error
|
182
|
+
end
|
171
183
|
end
|
172
184
|
|
173
185
|
describe '#>>' do
|