rom 3.0.0 → 3.0.1

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: 078640069bc820b095d68303b641a154635a91f6
4
- data.tar.gz: 79499e687dc324c807495be3e332cd27dee00002
3
+ metadata.gz: 9779926f8873d5ee6b2156b79ea81d295a25d4d6
4
+ data.tar.gz: 1c773434740d811cf17d0719947a362b2195a0d3
5
5
  SHA512:
6
- metadata.gz: cd576e0492c38c4b68ac39a7a9fe406d333035658d014541aa379698c08649064a93b1cb7db762d8c327d0f01fa1eb4b1e62c9d3693c83e1e97f0887286966c7
7
- data.tar.gz: e930878f5a01d11b9c2c1cd09e2fddfb91584ac7c2daca875acb06f772921bafaa8755dd7fcedece03c7b9ebe04d75f277f1f9a42efd01780db8f08de728b2dd
6
+ metadata.gz: bd347260359221fe2e8fb474f59c1d09407ed11a933682e963d80938fbf485eabf45f54e533b211a9e4bbd7f31b803e429cbb7790a31f01b2b9a6a46b3879686
7
+ data.tar.gz: 518d3e583b9bf233ad0624c0a029a83c9ef1d468b9e7ccae429bbd43267a6904cf883c5216dc98546c47fdee2e2e3d5940c9750863a54eda6bace8cfe759b0f7
@@ -1,4 +1,12 @@
1
- ## v3.0.0 to-be-released
1
+ ## v3.0.1 2017-02-01
2
+
3
+ ## Fixed
4
+
5
+ * ViewDSL exposes schemas that have access to all relations (solnic)
6
+
7
+ [Compare v3.0.0...v3.0.1](https://github.com/rom-rb/rom/compare/v3.0.0...v3.0.1)
8
+
9
+ ## v3.0.0 2017-01-29
2
10
 
3
11
  ## Added
4
12
 
@@ -224,6 +224,14 @@ module ROM
224
224
  # end
225
225
  # end
226
226
  #
227
+ # @example View with a schema extended with foreign attributes
228
+ # class Users < ROM::Relation[:sql]
229
+ # view(:index) do
230
+ # schema { append(relations[:tasks][:title]) }
231
+ # relation { |name| where(name: name) }
232
+ # end
233
+ # end
234
+ #
227
235
  # @return [Symbol] view method name
228
236
  #
229
237
  # @api public
@@ -330,9 +338,9 @@ module ROM
330
338
  # Hook to finalize a relation after its instance was created
331
339
  #
332
340
  # @api private
333
- def finalize(_container, relation)
341
+ def finalize(registry, relation)
334
342
  schemas = relation.schemas.reduce({}) do |h, (a, e)|
335
- h.update(a => e.is_a?(Proc) ? instance_exec(&e) : e)
343
+ h.update(a => e.is_a?(Proc) ? instance_exec(registry, &e) : e)
336
344
  end
337
345
  relation.schemas.update(schemas)
338
346
  relation
@@ -1,12 +1,26 @@
1
1
  module ROM
2
2
  class Relation
3
+ # ViewDSL is exposed in `Relation.view` method
4
+ #
5
+ # This is used to establish pre-defined relation views with explicit schemas.
6
+ # Such views can be used to compose relations together, even from multiple
7
+ # adapters.
8
+ #
9
+ # @api public
3
10
  class ViewDSL
11
+ # @!attribute [r] name
12
+ # @return [Symbol] The view name (relation method)
4
13
  attr_reader :name
5
14
 
15
+ # @!attribute [r] relation_block
16
+ # @return [Proc] The relation block that will be evaluated by the view method
6
17
  attr_reader :relation_block
7
18
 
19
+ # @!attribute [r] new_schema
20
+ # @return [Proc] The schema proc returned by the schema DSL
8
21
  attr_reader :new_schema
9
22
 
23
+ # @api private
10
24
  def initialize(name, schema, &block)
11
25
  @name = name
12
26
  @schema = schema
@@ -15,14 +29,33 @@ module ROM
15
29
  instance_eval(&block)
16
30
  end
17
31
 
32
+ # Define a schema for a relation view
33
+ #
34
+ # @return [Proc]
35
+ #
36
+ # @see Relation::ClassInterface.view
37
+ #
38
+ # @api public
18
39
  def schema(&block)
19
- @new_schema = -> { @schema.instance_exec(&block) }
40
+ @new_schema = -> relations { @schema.with(relations: relations).instance_exec(&block) }
20
41
  end
21
42
 
43
+ # Define a relation block for a relation view
44
+ #
45
+ # @return [Proc]
46
+ #
47
+ # @see Relation::ClassInterface.view
48
+ #
49
+ # @api public
22
50
  def relation(&block)
23
51
  @relation_block = lambda(&block)
24
52
  end
25
53
 
54
+ # Return procs captured by the DSL
55
+ #
56
+ # @return [Array]
57
+ #
58
+ # @api private
26
59
  def call
27
60
  [name, new_schema, relation_block]
28
61
  end
@@ -1,3 +1,3 @@
1
1
  module ROM
2
- VERSION = '3.0.0'.freeze
2
+ VERSION = '3.0.1'.freeze
3
3
  end
@@ -4,6 +4,18 @@ require 'rom/memory'
4
4
  RSpec.describe ROM::Relation, '.view' do
5
5
  subject(:relation) { relation_class.new(ROM::Memory::Dataset.new([])) }
6
6
 
7
+ let(:registry) do
8
+ { tasks: tasks }
9
+ end
10
+
11
+ let(:tasks) do
12
+ Class.new(ROM::Relation[:memory]) do
13
+ schema do
14
+ attribute :title, ROM::Types::String
15
+ end
16
+ end.new([])
17
+ end
18
+
7
19
  it 'returns view method name' do
8
20
  klass = Class.new(ROM::Relation[:memory]) {
9
21
  schema { attribute :id, ROM::Types::Int }
@@ -20,6 +32,10 @@ RSpec.describe ROM::Relation, '.view' do
20
32
  relation << { id: 2, name: 'Jane' }
21
33
  end
22
34
 
35
+ it 'appends foreign attributes' do
36
+ expect(relation.schemas[:foreign_attributes].map(&:name)).to eql(%i[id name title])
37
+ end
38
+
23
39
  it 'uses projected schema for view schema' do
24
40
  expect(relation.schemas[:names].map(&:name)).to eql(%i[name])
25
41
  end
@@ -44,7 +60,7 @@ RSpec.describe ROM::Relation, '.view' do
44
60
  context 'with an explicit schema' do
45
61
  before do
46
62
  # this is normally called automatically during setup
47
- relation_class.finalize({}, relation)
63
+ relation_class.finalize(registry, relation)
48
64
  end
49
65
 
50
66
  include_context 'relation with views' do
@@ -55,6 +71,16 @@ RSpec.describe ROM::Relation, '.view' do
55
71
  attribute :name, ROM::Types::String
56
72
  end
57
73
 
74
+ view(:foreign_attributes) do
75
+ schema do
76
+ append(relations[:tasks][:title])
77
+ end
78
+
79
+ relation do
80
+ self
81
+ end
82
+ end
83
+
58
84
  view(:names) do
59
85
  schema do
60
86
  project(:name)
@@ -83,7 +109,7 @@ RSpec.describe ROM::Relation, '.view' do
83
109
  before do
84
110
  # this is normally called automatically during setup
85
111
  relation_class.schema.finalize!
86
- relation_class.finalize({}, relation)
112
+ relation_class.finalize(registry, relation)
87
113
  end
88
114
 
89
115
  include_context 'relation with views' do
@@ -96,6 +122,16 @@ RSpec.describe ROM::Relation, '.view' do
96
122
 
97
123
  schema(:users, infer: true)
98
124
 
125
+ view(:foreign_attributes) do
126
+ schema do
127
+ append(relations[:tasks][:title])
128
+ end
129
+
130
+ relation do
131
+ self
132
+ end
133
+ end
134
+
99
135
  view(:names) do
100
136
  schema do
101
137
  project(:name)
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
4
+ version: 3.0.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: 2017-01-29 00:00:00.000000000 Z
11
+ date: 2017-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -397,7 +397,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
397
397
  version: '0'
398
398
  requirements: []
399
399
  rubyforge_project:
400
- rubygems_version: 2.5.1
400
+ rubygems_version: 2.6.9
401
401
  signing_key:
402
402
  specification_version: 4
403
403
  summary: Ruby Object Mapper