rom 3.0.0.beta1 → 3.0.0.beta2

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: 58d0cbbb31e4ac734e6b569dcd7c0a1bd679bd89
4
- data.tar.gz: d6f72e2b130a21ba81cc66400be6da7ea179aa6c
3
+ metadata.gz: 7783cc66c1b765933756f1ac1aa1c90d37e457c3
4
+ data.tar.gz: b7303d0198ff50269246903fe532500a94fd4829
5
5
  SHA512:
6
- metadata.gz: 3ae3f83681a32b2f51629a49ab3ecde5c66d2ce2ce59e6dfdb36475343a73ff4515bda9e5aa5b7ab59fb7fd81777296ee7b98b221af621f1f37bd4ae42159442
7
- data.tar.gz: b688b6b8430a4f9bbe4dd43dbe066813aa354adc5d0e519107be7c3c8e226abb8498c06c2bbbd4042d6498a2ea0c63e63a73396ad1fddf342740a1c438c14045
6
+ metadata.gz: 228c165ca9052fc4a50963fc17929ff0f1eb6ee94a856df11d0d9dc58eae5118f908c9dbb58db4f50071a9398bf92afbd28e247f8f15753d31edc25ea76494a9
7
+ data.tar.gz: 836531fb06c233cdee08a8cad06c648bc498095a7914d50f3dc25553dab7e761d912b38dde9f9fcbd9638db5381e6a0506798b1e455d77c58af6360e8dc29ea3
data/Gemfile CHANGED
@@ -2,8 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rom-mapper', git: 'https://github.com/rom-rb/rom-mapper.git', branch: 'master'
6
-
7
5
  group :console do
8
6
  gem 'pry'
9
7
  gem 'pg', platforms: [:mri]
data/lib/rom/constants.rb CHANGED
@@ -22,6 +22,12 @@ module ROM
22
22
  UnsupportedRelationError = Class.new(StandardError)
23
23
  MissingAdapterIdentifierError = Class.new(StandardError)
24
24
 
25
+ MissingSchemaClassError = Class.new(StandardError) do
26
+ def initialize(klass)
27
+ super("#{klass.inspect} relation is missing schema_class")
28
+ end
29
+ end
30
+
25
31
  DuplicateConfigurationError = Class.new(StandardError)
26
32
  DuplicateContainerError = Class.new(StandardError)
27
33
 
@@ -30,7 +30,11 @@ module ROM
30
30
  end
31
31
 
32
32
  klass.extend Dry::Core::ClassAttributes
33
- klass.defines :adapter, :schema_class
33
+ klass.defines :adapter, :schema_class, :schema_inferrer, :schema_dsl
34
+
35
+ klass.schema_dsl Schema::DSL
36
+ klass.schema_class Schema
37
+ klass.schema_inferrer Schema::DEFAULT_INFERRER
34
38
 
35
39
  # Extend with functionality required by adapters *only* if this is a direct
36
40
  # descendant of an adapter-specific relation subclass
@@ -39,13 +43,9 @@ module ROM
39
43
  klass.class_eval do
40
44
  use :registry_reader
41
45
 
42
- defines :gateway, :dataset, :dataset_proc, :register_as,
43
- :schema_dsl, :schema_inferrer
46
+ defines :gateway, :dataset, :dataset_proc, :register_as
44
47
 
45
48
  gateway :default
46
- schema_dsl Schema::DSL
47
- schema_class Schema
48
- schema_inferrer nil
49
49
 
50
50
  dataset default_name
51
51
 
@@ -160,15 +160,25 @@ module ROM
160
160
  # @param [Boolean] infer Whether to do an automatic schema inferring
161
161
  #
162
162
  # @api public
163
- def schema(dataset = nil, infer: false, &block)
163
+ def schema(dataset = nil, as: nil, infer: false, &block)
164
164
  if defined?(@schema)
165
165
  @schema
166
166
  elsif block || infer
167
167
  self.dataset(dataset) if dataset
168
- self.register_as(self.dataset) unless register_as
168
+
169
+ if as
170
+ self.register_as(as)
171
+ else
172
+ self.register_as(self.dataset) unless register_as
173
+ end
169
174
 
170
175
  name = Name[register_as, self.dataset]
171
176
  inferrer = infer ? schema_inferrer : nil
177
+
178
+ unless schema_class
179
+ raise MissingSchemaClassError.new(self)
180
+ end
181
+
172
182
  dsl = schema_dsl.new(name, schema_class: schema_class, inferrer: inferrer, &block)
173
183
 
174
184
  @schema = dsl.call
@@ -283,6 +293,12 @@ module ROM
283
293
  @schemas ||= {}
284
294
  end
285
295
 
296
+ # @api private
297
+ def default_schema(relation)
298
+ relation_class = relation.class
299
+ relation_class.schema || relation_class.schema_class.define(relation_class.default_name)
300
+ end
301
+
286
302
  # Hook to finalize a relation after its instance was created
287
303
  #
288
304
  # @api private
data/lib/rom/relation.rb CHANGED
@@ -51,9 +51,7 @@ module ROM
51
51
  # schema (if it was defined) and sets an empty one as
52
52
  # the fallback
53
53
  # @api public
54
- option :schema, reader: true, optional: true, default: -> relation {
55
- relation.class.schema || Schema.define(Dry::Core::Inflector.underscore(relation.class.name || EMPTY_STRING).to_sym)
56
- }
54
+ option :schema, reader: true, default: method(:default_schema).to_proc
57
55
 
58
56
  # @!attribute [r] schema_hash
59
57
  # @return [Object#[]] tuple processing function, uses schema or defaults to Hash[]
data/lib/rom/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ROM
2
- VERSION = '3.0.0.beta1'.freeze
2
+ VERSION = '3.0.0.beta2'.freeze
3
3
  end
@@ -16,7 +16,7 @@ RSpec.describe 'Mapper definition DSL' do
16
16
  { type: 'home' },
17
17
  {}
18
18
  ])
19
- users.insert(name: 'Jane')
19
+ users.insert(name: 'Jane', emails: [])
20
20
  end
21
21
 
22
22
  describe 'ungroup' do
@@ -85,6 +85,24 @@ RSpec.describe ROM::Relation, '.schema' do
85
85
  expect(Test::Users.register_as).to be(:test_users)
86
86
  end
87
87
 
88
+ it 'allows setting both dataset and relation alias' do
89
+ class Test::Users < ROM::Relation[:memory]
90
+ schema(:test_users, as: :users) { }
91
+ end
92
+
93
+ expect(Test::Users.register_as).to be(:users)
94
+ expect(Test::Users.dataset).to be(:test_users)
95
+ end
96
+
97
+ it 'raises error when schema_class is missing' do
98
+ class Test::Users < ROM::Relation[:memory]
99
+ schema_class nil
100
+ end
101
+
102
+ expect { Test::Users.schema(:test) { } }.
103
+ to raise_error(ROM::MissingSchemaClassError, "Test::Users relation is missing schema_class")
104
+ end
105
+
88
106
  describe '#schema' do
89
107
  it 'returns defined schema' do
90
108
  class Test::Users < ROM::Relation[:memory]
@@ -219,14 +219,15 @@ RSpec.describe ROM::Relation do
219
219
 
220
220
  describe '#schema' do
221
221
  it 'returns an empty schema by default' do
222
- relation = Class.new(ROM::Relation[:memory]) {
222
+ relation = Class.new(ROM::Relation) {
223
223
  def self.name
224
- 'SomeRelation'
224
+ 'Test::SomeRelation'
225
225
  end
226
226
  }.new([])
227
227
 
228
228
  expect(relation.schema).to be_empty
229
- expect(relation.schema.name).to be(:some_relation)
229
+ expect(relation.schema.inferrer).to be(ROM::Schema::DEFAULT_INFERRER)
230
+ expect(relation.schema.name).to be(:test_some_relation)
230
231
  expect(relation.schema?).to be(false)
231
232
  end
232
233
  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.0.beta1
4
+ version: 3.0.0.beta2
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-01-09 00:00:00.000000000 Z
11
+ date: 2017-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby