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.
@@ -167,7 +167,7 @@ module ROM
167
167
  else
168
168
  arity = relation.method(meth).arity
169
169
 
170
- if arity == -1 || arity == args.size
170
+ if arity < 0 || arity == args.size
171
171
  response = relation.__send__(meth, *args, &block)
172
172
  if response.is_a?(Relation)
173
173
  __new__(response)
@@ -4,7 +4,7 @@ module ROM
4
4
  # @api private
5
5
  def self.included(klass)
6
6
  super
7
- klass.option :__registry__, type: Hash, default: {}, reader: true
7
+ klass.option :__registry__, type: Hash, default: EMPTY_HASH, reader: true
8
8
  end
9
9
 
10
10
  # @api private
@@ -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, readers)
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
@@ -1,3 +1,3 @@
1
1
  module ROM
2
- VERSION = '0.6.0.beta3'.freeze
2
+ VERSION = '0.6.0.rc1'.freeze
3
3
  end
@@ -1,6 +1,8 @@
1
1
  desc "Run benchmarks (tweak count via COUNT envvar)"
2
2
  task :benchmark do
3
- sh "ruby benchmarks/basic.rb"
3
+ FileList["benchmarks/**/*_bench.rb"].each do |bench|
4
+ sh "ruby #{bench}"
5
+ end
4
6
  end
5
7
 
6
8
  namespace :benchmark do
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', '~> 0.1'
20
- gem.add_runtime_dependency 'equalizer', '~> 0.0', '>= 0.0.9'
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'
@@ -33,7 +33,7 @@ describe 'Mappers / deeply embedded tuples' do
33
33
  ]
34
34
  }
35
35
 
36
- jane = rom.read(:users).to_a.first
36
+ jane = rom.relation(:users).as(:users).first
37
37
 
38
38
  expect(jane.name).to eql('Jane')
39
39
 
@@ -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.read(:users).mapper }
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.read(:users).email_index.mapper }
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.read(:users).email_index.mapper }
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.read(:tasks).with_user.to_a.last
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.read(:tasks).with_user.to_a.last
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.read(:tasks).with_user.to_a.last
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.read(:users).to_a.first
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.read(:users).to_a.first
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.read(:users).with_tasks.to_a.last
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.read(:users).with_tasks.to_a.last
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.read(:users).with_tasks.to_a.last
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.read(:tasks).with_users.to_a.first
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.read(:users).to_a.first
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.read(:users).to_a.first
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.read(:users).with_address.first
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.read(:users).with_addresses.first
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.read(:users).first
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.read(:tasks).first
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.read(:tasks).with_user.to_a.last
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.read(:tasks).with_user.to_a.last
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.read(:tasks).with_user.to_a.last
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.read(:tasks).with_user.to_a.last
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
- expect(rom.read(:users_and_tasks).by_user('Jane').to_a).to eql([
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.read(:users).sorted.by_name('Jane')
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
- keys = rom.read(:users).with_tasks.header.keys
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
- expect(rom.read(:users)).to_not respond_to(:join)
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
- keys = rom.read(:users).with_task.header.keys
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.read(:users).by_name("Jane").first
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.read(:users).map(:prefixer).first
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.readers).to eql(ROM::ReaderRegistry.new)
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.read(:users).by_name('Jane').to_a)
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.read(:users).by_name('Jane').to_a)
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
@@ -46,7 +46,7 @@ describe ROM::Env do
46
46
 
47
47
  describe '#mappers' do
48
48
  it 'returns mappers for all relations' do
49
- expect(rom.mappers.users).to eql(rom.readers.users.mappers)
49
+ expect(rom.mappers.users[:name_list]).to_not be(nil)
50
50
  end
51
51
  end
52
52
  end
@@ -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