rom 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9779926f8873d5ee6b2156b79ea81d295a25d4d6
4
- data.tar.gz: 1c773434740d811cf17d0719947a362b2195a0d3
3
+ metadata.gz: e937480122a0f25c272a123788205fca636c3914
4
+ data.tar.gz: 14f714ced390387ee4e3008c6ac7028ec3ffb342
5
5
  SHA512:
6
- metadata.gz: bd347260359221fe2e8fb474f59c1d09407ed11a933682e963d80938fbf485eabf45f54e533b211a9e4bbd7f31b803e429cbb7790a31f01b2b9a6a46b3879686
7
- data.tar.gz: 518d3e583b9bf233ad0624c0a029a83c9ef1d468b9e7ccae429bbd43267a6904cf883c5216dc98546c47fdee2e2e3d5940c9750863a54eda6bace8cfe759b0f7
6
+ metadata.gz: f88ca6fd4d17cce1332c5005f422e4b8fbbfa86e4acd72e602b89322b1a35f22ab8a176fa1dd5e497de78e32432e133b6cc9ba8e08b9d4ac6bf54e65dd0feccd
7
+ data.tar.gz: b2e112e5baaa3d27b035ef18143b81576c1a86fda420e2ad8d96e350f4b7ad7a8328f03c8edc12b6b1f927af3d9d1f3d210eb048c7c5e5733c08a67d466c8b0c
data/CHANGELOG.md CHANGED
@@ -1,4 +1,17 @@
1
- ## v3.0.1 2017-02-01
1
+ # v3.0.2 2017-02-24
2
+
3
+ ## Added
4
+
5
+ * `Schema::Attribute#key` which returns tuple key name, either alias or canonical name (solnic)
6
+
7
+ ## Fixed
8
+
9
+ * Fix the error message for missing association (flash-gordon)
10
+ * Curried relation called without any arguments will raise an ArgumentError (solnic)
11
+
12
+ [Compare v3.0.1...v3.0.2](https://github.com/rom-rb/rom/compare/v3.0.1...v3.0.2)
13
+
14
+ # v3.0.1 2017-02-01
2
15
 
3
16
  ## Fixed
4
17
 
@@ -6,7 +19,7 @@
6
19
 
7
20
  [Compare v3.0.0...v3.0.1](https://github.com/rom-rb/rom/compare/v3.0.0...v3.0.1)
8
21
 
9
- ## v3.0.0 2017-01-29
22
+ # v3.0.0 2017-01-29
10
23
 
11
24
  ## Added
12
25
 
@@ -40,7 +53,7 @@
40
53
 
41
54
  [Compare v2.0.2...v3.0.0](https://github.com/rom-rb/rom/compare/v2.0.2...v3.0.0)
42
55
 
43
- ## v2.0.2 2016-11-11
56
+ # v2.0.2 2016-11-11
44
57
 
45
58
  ## Added
46
59
 
@@ -53,7 +66,7 @@
53
66
 
54
67
  [Compare v2.0.1...v2.0.2](https://github.com/rom-rb/rom/compare/v2.0.1...v2.0.2)
55
68
 
56
- ## v2.0.1 2016-09-30
69
+ # v2.0.1 2016-09-30
57
70
 
58
71
  ### Added
59
72
 
@@ -66,7 +79,7 @@
66
79
 
67
80
  [Compare v2.0.0...v2.0.1](https://github.com/rom-rb/rom/compare/v2.0.0...v2.0.1)
68
81
 
69
- ## v2.0.0 2016-07-27
82
+ # v2.0.0 2016-07-27
70
83
 
71
84
  ### Added
72
85
 
@@ -104,7 +117,7 @@
104
117
 
105
118
  [Compare v1.0.0...v2.0.0](https://github.com/rom-rb/rom/compare/v1.0.0...v2.0.0)
106
119
 
107
- ## v1.0.0 2016-01-06
120
+ # v1.0.0 2016-01-06
108
121
 
109
122
  ### Added
110
123
 
@@ -132,7 +145,7 @@
132
145
 
133
146
  [Compare v0.9.1...v1.0.0](https://github.com/rom-rb/rom/compare/v0.9.1...v1.0.0)
134
147
 
135
- ## v0.9.1 2015-08-21
148
+ # v0.9.1 2015-08-21
136
149
 
137
150
  This is a small bug-fix release which addresses a couple of issues for inline
138
151
  setup DSL and multi-environments.
@@ -152,7 +165,7 @@ setup DSL and multi-environments.
152
165
 
153
166
  [Compare v0.9.0...v0.9.1](https://github.com/rom-rb/rom/compare/v0.9.0...v0.9.1)
154
167
 
155
- ## v0.9.0 2015-08-19
168
+ # v0.9.0 2015-08-19
156
169
 
157
170
  ### Added
158
171
 
@@ -184,7 +197,7 @@ setup DSL and multi-environments.
184
197
 
185
198
  [Compare v0.8.1...v0.9.0](https://github.com/rom-rb/rom/compare/v0.8.1...v0.9.0)
186
199
 
187
- ## v0.8.1 2015-07-12
200
+ # v0.8.1 2015-07-12
188
201
 
189
202
  ### Fixed
190
203
 
@@ -196,7 +209,7 @@ setup DSL and multi-environments.
196
209
 
197
210
  [Compare v0.8.0...v0.8.1](https://github.com/rom-rb/rom/compare/v0.8.0...v0.8.1)
198
211
 
199
- ## v0.8.0 2015-06-22
212
+ # v0.8.0 2015-06-22
200
213
 
201
214
  ### Added
202
215
 
@@ -224,7 +237,7 @@ setup DSL and multi-environments.
224
237
 
225
238
  [Compare v0.7.1...v0.8.0](https://github.com/rom-rb/rom/compare/v0.7.1...v0.8.0)
226
239
 
227
- ## v0.7.1 2015-05-22
240
+ # v0.7.1 2015-05-22
228
241
 
229
242
  ### Added
230
243
 
@@ -242,7 +255,7 @@ setup DSL and multi-environments.
242
255
 
243
256
  [Compare v0.7.0...v0.7.1](https://github.com/rom-rb/rom/compare/v0.7.0...v0.7.1)
244
257
 
245
- ## v0.7.0 2015-05-17
258
+ # v0.7.0 2015-05-17
246
259
 
247
260
  ### Added
248
261
 
@@ -276,7 +289,7 @@ setup DSL and multi-environments.
276
289
 
277
290
  [Compare v0.6.2...v0.7.0](https://github.com/rom-rb/rom/compare/v0.6.2...v0.7.0)
278
291
 
279
- ## v0.6.2 2015-04-14
292
+ # v0.6.2 2015-04-14
280
293
 
281
294
  ### Changed
282
295
 
@@ -288,7 +301,7 @@ setup DSL and multi-environments.
288
301
 
289
302
  [Compare v0.6.1...v0.6.2](https://github.com/rom-rb/rom/compare/v0.6.1...v0.6.2)
290
303
 
291
- ## v0.6.1 2015-04-04
304
+ # v0.6.1 2015-04-04
292
305
 
293
306
  ### Added
294
307
 
@@ -301,7 +314,7 @@ setup DSL and multi-environments.
301
314
 
302
315
  [Compare v0.6.0...v0.6.1](https://github.com/rom-rb/rom/compare/v0.6.0...v0.6.1)
303
316
 
304
- ## v0.6.0 2015-03-22
317
+ # v0.6.0 2015-03-22
305
318
 
306
319
  ### Added
307
320
 
@@ -342,7 +355,7 @@ setup DSL and multi-environments.
342
355
 
343
356
  [Compare v0.5.0...v0.6.0](https://github.com/rom-rb/rom/compare/v0.5.0...v0.6.0)
344
357
 
345
- ## v0.5.0 2014-12-31
358
+ # v0.5.0 2014-12-31
346
359
 
347
360
  ### Added
348
361
 
@@ -383,7 +396,7 @@ setup DSL and multi-environments.
383
396
 
384
397
  [Compare v0.4.2...v0.5.0](https://github.com/rom-rb/rom/compare/v0.4.2...v0.5.0)
385
398
 
386
- ## v0.4.2 2014-12-19
399
+ # v0.4.2 2014-12-19
387
400
 
388
401
  ### Added
389
402
 
@@ -399,7 +412,7 @@ setup DSL and multi-environments.
399
412
 
400
413
  [Compare v0.4.1...v0.4.2](https://github.com/rom-rb/rom/compare/v0.4.1...v0.4.2)
401
414
 
402
- ## v0.4.1 2014-12-15
415
+ # v0.4.1 2014-12-15
403
416
 
404
417
  ### Added
405
418
 
@@ -416,7 +429,7 @@ setup DSL and multi-environments.
416
429
 
417
430
  [Compare v0.4.0...v0.4.1](https://github.com/rom-rb/rom/compare/v0.4.0...v0.4.1)
418
431
 
419
- ## v0.4.0 2014-12-06
432
+ # v0.4.0 2014-12-06
420
433
 
421
434
  ### Added
422
435
 
@@ -436,7 +449,7 @@ setup DSL and multi-environments.
436
449
 
437
450
  [Compare v0.3.1...v0.4.0](https://github.com/rom-rb/rom/compare/v0.3.1...v0.4.0)
438
451
 
439
- ## v0.3.1 2014-11-25
452
+ # v0.3.1 2014-11-25
440
453
 
441
454
  ### Added
442
455
 
@@ -452,14 +465,14 @@ setup DSL and multi-environments.
452
465
 
453
466
  [Compare v0.3.0...v0.3.1](https://github.com/rom-rb/rom/compare/v0.3.0...v0.3.1)
454
467
 
455
- ## v0.3.0 2014-11-24
468
+ # v0.3.0 2014-11-24
456
469
 
457
470
  This version is a rewrite that introduces a new, simplified architecture based
458
471
  on a new adapter interface.
459
472
 
460
473
  [Compare v0.2.0...v0.3.0](https://github.com/rom-rb/rom/compare/v0.2.0...v0.3.0)
461
474
 
462
- ## v0.2.0 2014-04-06
475
+ # v0.2.0 2014-04-06
463
476
 
464
477
  ### Added
465
478
 
@@ -482,19 +495,19 @@ on a new adapter interface.
482
495
 
483
496
  [Compare v0.1.2...v0.2.0](https://github.com/rom-rb/rom/compare/v0.1.2...v0.2.0)
484
497
 
485
- ## v0.1.2 2013-09-02
498
+ # v0.1.2 2013-09-02
486
499
 
487
500
  * [updated] [rom-relation](https://github.com/rom-rb/rom-relation/blob/v0.1.2/Changelog.md#v012-2013-09-02)
488
501
 
489
502
  [Compare v0.1.1...v0.1.2](https://github.com/rom-rb/rom/compare/v0.1.1...v0.1.2)
490
503
 
491
- ## v0.1.1 2013-08-30
504
+ # v0.1.1 2013-08-30
492
505
 
493
506
  * [updated] [rom-relation](https://github.com/rom-rb/rom-relation/blob/v0.1.1/Changelog.md#v011-2013-08-30)
494
507
  * [updated] [rom-session](https://github.com/rom-rb/rom-session/blob/v0.1.1/Changelog.md#v011-2013-08-30)
495
508
 
496
509
  [Compare v0.1.0...v0.1.1](https://github.com/rom-rb/rom/compare/v0.1.0...v0.1.1)
497
510
 
498
- ## v0.1.0 2013-08-23
511
+ # v0.1.0 2013-08-23
499
512
 
500
513
  First public release
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2014 Ruby Object Mapper Team
1
+ Copyright (c) 2013-2017 Ruby Object Mapper Team
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -21,10 +21,17 @@ module ROM
21
21
  if key?(key)
22
22
  super
23
23
  else
24
- super(singularize(key))
24
+ sk = singularize(key)
25
+
26
+ if key?(sk)
27
+ super(sk)
28
+ else
29
+ super
30
+ end
25
31
  end
26
32
  end
27
33
 
34
+ # @api private
28
35
  def singularize(key)
29
36
  Dry::Core::Inflector.singularize(key).to_sym
30
37
  end
@@ -38,6 +38,8 @@ module ROM
38
38
 
39
39
  if arity == all_args.size
40
40
  Loaded.new(relation.__send__(name.relation, *all_args))
41
+ elsif args.empty?
42
+ raise ArgumentError, "curried #{relation.class}##{name.to_sym} relation was called without any arguments"
41
43
  else
42
44
  __new__(relation, curry_args: all_args)
43
45
  end
data/lib/rom/schema.rb CHANGED
@@ -227,7 +227,7 @@ module ROM
227
227
  #
228
228
  # @api public
229
229
  def wrap(prefix = name.dataset)
230
- new(map { |attr| attr.wrapped(prefix) })
230
+ new(map { |attr| attr.wrapped? ? attr : attr.wrapped(prefix) })
231
231
  end
232
232
 
233
233
  # Return FK attribute for a given relation name
@@ -342,7 +342,7 @@ module ROM
342
342
  # @api private
343
343
  def to_output_hash
344
344
  Types::Coercible::Hash.schema(
345
- map { |attr| [attr.name, attr.to_read_type] }.to_h
345
+ map { |attr| [attr.key, attr.to_read_type] }.to_h
346
346
  )
347
347
  end
348
348
 
@@ -173,6 +173,31 @@ module ROM
173
173
  meta[:name]
174
174
  end
175
175
 
176
+ # Return tuple key
177
+ #
178
+ # When schemas are projected with aliased attributes, we need a simple access to tuple keys
179
+ #
180
+ # @example
181
+ # class Tasks < ROM::Relation[:memory]
182
+ # schema do
183
+ # attribute :user_id, Types::Int.meta(alias: :id)
184
+ # attribute :name, Types::String
185
+ # end
186
+ # end
187
+ #
188
+ # Users.schema[:id].key
189
+ # # :id
190
+ #
191
+ # Users.schema.project(Users.schema[:id].aliased(:user_id)).key
192
+ # # :user_id
193
+ #
194
+ # @return [Symbol]
195
+ #
196
+ # @api public
197
+ def key
198
+ meta[:alias] || name
199
+ end
200
+
176
201
  # Return attribute's alias
177
202
  #
178
203
  # @example
data/lib/rom/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ROM
2
- VERSION = '3.0.1'.freeze
2
+ VERSION = '3.0.2'.freeze
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- if ENV['COVERAGE'] == 'true' && RUBY_ENGINE == 'ruby' && RUBY_VERSION == '2.3.1'
1
+ if ENV['COVERAGE'] == 'true' && RUBY_ENGINE == 'ruby' && RUBY_VERSION == '2.4.0'
2
2
  require "simplecov"
3
3
  SimpleCov.start do
4
4
  add_filter '/spec/'
@@ -24,4 +24,25 @@ RSpec.describe ROM::AssociationSet do
24
24
  expect(fallback).to have_received(:done)
25
25
  end
26
26
  end
27
+
28
+ describe '#[]' do
29
+ let(:users) { BasicObject.new }
30
+ let(:posts) { BasicObject.new }
31
+ let(:set) { ROM::AssociationSet.new(users: users, post: posts) }
32
+
33
+ it 'fetches association' do
34
+ expect(set[:users]).to be users
35
+ end
36
+
37
+ it 'tries to fetch under singularized key' do
38
+ expect(set[:post]).to be posts
39
+ end
40
+
41
+ it 'throws exception on missing association' do
42
+ expect { set[:labels] }.to raise_error(
43
+ ROM::Registry::ElementNotFoundError,
44
+ ":labels doesn't exist in ROM::AssociationSet registry"
45
+ )
46
+ end
47
+ end
27
48
  end
@@ -17,16 +17,21 @@ RSpec.describe ROM::Relation::Curried do
17
17
  end
18
18
 
19
19
  describe '#call' do
20
- let(:relation) { users_relation.by_name.call('Jane') }
20
+ let(:relation) { users_relation.by_name }
21
21
 
22
22
  it 'materializes a relation' do
23
- expect(relation).to match_array([
24
- name: 'Jane', email: 'jane@doe.org'
25
- ])
23
+ expect(relation.('Jane').to_a).to eql([name: 'Jane', email: 'jane@doe.org'])
26
24
  end
27
25
 
28
26
  it 'returns a loaded relation' do
29
- expect(relation.source).to eql(users_relation.by_name('Jane'))
27
+ expect(relation.('Jane').source).to eql(users_relation.by_name('Jane'))
28
+ end
29
+
30
+ it 'raises argument error if no arguments were provided' do
31
+ expect { relation.() }.
32
+ to raise_error(
33
+ ArgumentError,
34
+ "curried #{users_relation.class}#by_name relation was called without any arguments")
30
35
  end
31
36
  end
32
37
 
@@ -0,0 +1,28 @@
1
+ require 'rom/memory'
2
+
3
+ RSpec.describe ROM::Relation, '#output_schema' do
4
+ subject(:relation) do
5
+ Class.new(ROM::Relation[:memory]) do
6
+ schema do
7
+ attribute :id, ROM::Types::String, read: ROM::Types::Int
8
+ attribute :name, ROM::Types::String
9
+ end
10
+ end.new(ROM::Memory::Dataset.new([]))
11
+ end
12
+
13
+ let(:schema) do
14
+ relation.schema
15
+ end
16
+
17
+ it 'returns output_schema based on canonical schema' do
18
+ expect(relation.output_schema).
19
+ to eql(ROM::Types::Coercible::Hash.schema(id: schema[:id].to_read_type, name: schema[:name].type))
20
+ end
21
+
22
+ it 'returns output_schema based on projected schema' do
23
+ projected = relation.project(schema[:id].aliased(:user_id))
24
+
25
+ expect(projected.output_schema).
26
+ to eql(ROM::Types::Coercible::Hash.schema(user_id: projected.schema[:id].to_read_type))
27
+ end
28
+ end
@@ -13,5 +13,6 @@ RSpec.describe ROM::Schema, '#wrap' do
13
13
  expect(wrapped.map(&:alias)).to eql(%i[users_id users_name])
14
14
  expect(wrapped.map { |attr| attr.meta[:name] }).to eql(%i[id name])
15
15
  expect(wrapped.all?(&:wrapped?)).to be(true)
16
+ expect(wrapped.wrap(:foo)).to eql(wrapped)
16
17
  end
17
18
  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: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-01 00:00:00.000000000 Z
11
+ date: 2017-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -360,6 +360,7 @@ files:
360
360
  - spec/unit/rom/relation/lazy_spec.rb
361
361
  - spec/unit/rom/relation/loaded_spec.rb
362
362
  - spec/unit/rom/relation/name_spec.rb
363
+ - spec/unit/rom/relation/output_schema_spec.rb
363
364
  - spec/unit/rom/relation/schema_spec.rb
364
365
  - spec/unit/rom/relation/view_spec.rb
365
366
  - spec/unit/rom/relation_spec.rb