rom-repository 1.0.0.beta1 → 1.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: a5e3e3120dbe44e4f2f116cfe7aaaba6b2ef0a7e
4
- data.tar.gz: 1e29da4f4c4c2c8c6cf7d9a70c794365419bc18d
3
+ metadata.gz: cdb0dfc90b48097d286f0d5b79790560d79c8fdd
4
+ data.tar.gz: ed15356517cc1dff17729d851e53b77f75727075
5
5
  SHA512:
6
- metadata.gz: b40d4d1a1c984998a0f58287cf586dd151251f9e9cabddcf22fff0a23e944f7113a1ffef5be76e6c44560d99d9c4d7bcecbb78f074f5079057ac71f7da0708a8
7
- data.tar.gz: 8ec19211a0103e67f33578166bb781c1d42271d04e5561451e023aaccc4722d90b9e2fa3061cc1a021efca5c5f13fad00b105f9d72cfb66c1a4f86a679422c13
6
+ metadata.gz: cc5b70717bbfb200cad2dc539f89c438398ae3dd3c6fb3f10f8d1c58c48e2be2b5d7bc01a729f738400e9b5021dbb070aa14fbdaec98c5ec8f30b57511e6448c
7
+ data.tar.gz: 88d6e30ab3107d583119ab1ed2a48bb83e138b2bc5026235acbb1a6932302a34037bb5315de976479d0c58895cb841026fe3239f8c3326e2093d882faf84942e
data/CHANGELOG.md CHANGED
@@ -11,6 +11,7 @@
11
11
  * Ability to define custom changeset classes that can be instantiated via `repo.changeset(MyChangesetClass[:rel_name]).data(some_data)` where `MyChangesetClass` inherits from a core changeset class (solnic)
12
12
  * `Changeset.map` which accepts a block and exposes a DSL for data transformations (all [transproc hash methods](https://github.com/solnic/transproc)) are available (solnic)
13
13
  * `Changeset#associate` method that accepts another changeset or parent data and an association identifier, ie `post_changeset.associate(user, :author)` (solnic)
14
+ * You can now use `wrap_parent` in combined relations too (which is gazillion times faster than `combine_parents`) (solnic)
14
15
 
15
16
  ### Changed
16
17
 
@@ -169,7 +169,7 @@ module ROM
169
169
 
170
170
  finalize_command_class(klass, relation)
171
171
 
172
- registry[rel_name][type] = klass.build(relation, input: relation.schema_hash)
172
+ registry[rel_name][type] = klass.build(relation, input: relation.input_schema)
173
173
  end
174
174
  end
175
175
 
@@ -84,7 +84,7 @@ module ROM
84
84
  #
85
85
  # @api private
86
86
  def with(new_options)
87
- __new__(relation, new_options)
87
+ __new__(relation, options.merge(new_options))
88
88
  end
89
89
 
90
90
  # Returns if this relation is combined aka a relation graph
@@ -189,7 +189,7 @@ module ROM
189
189
  #
190
190
  # @api private
191
191
  def wraps
192
- meta.fetch(:wraps, [])
192
+ meta.fetch(:wraps, EMPTY_ARRAY)
193
193
  end
194
194
 
195
195
  # Forward to relation and wrap it with proxy if response was a relation too
@@ -17,7 +17,7 @@ module ROM
17
17
  # @api private
18
18
  def combined(name, keys, type)
19
19
  meta = { keys: keys, combine_type: type, combine_name: name }
20
- with(name: name, meta: meta)
20
+ with(name: name, meta: self.meta.merge(meta))
21
21
  end
22
22
 
23
23
  # Combine with other relations
@@ -38,7 +38,8 @@ module ROM
38
38
  def wrap_parent(options)
39
39
  wrap(
40
40
  options.each_with_object({}) { |(name, parent), h|
41
- h[name] = [parent, combine_keys(parent, relation, :children)]
41
+ keys = combine_keys(parent, relation, :children)
42
+ h[name] = [parent, keys]
42
43
  }
43
44
  )
44
45
  end
@@ -50,9 +50,7 @@ module ROM
50
50
  end
51
51
 
52
52
  def visit_attribute(attr)
53
- unless attr.foreign_key?
54
- [attr.aliased? && !attr.wrapped? ? attr.alias : attr.name, attr.type]
55
- end
53
+ [attr.aliased? && !attr.wrapped? ? attr.alias : attr.name, attr.type]
56
54
  end
57
55
 
58
56
  def build_class(name, parent, &block)
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  class Repository
3
- VERSION = '1.0.0.beta1'.freeze
3
+ VERSION = '1.0.0.beta2'.freeze
4
4
  end
5
5
  end
@@ -37,9 +37,9 @@ RSpec.describe ROM::Repository, '#command' do
37
37
  expect(user.name).to eql('Jane Doe')
38
38
  end
39
39
 
40
- it 'uses schema_hash for command input' do
40
+ it 'uses input_schema for command input' do
41
41
  create_user = repo.command(create: :users)
42
- expect(create_user.input).to eql(repo.users.schema_hash)
42
+ expect(create_user.input).to eql(repo.users.input_schema)
43
43
  end
44
44
 
45
45
  it 'caches commands' do
@@ -95,6 +95,17 @@ RSpec.describe 'ROM repository' do
95
95
  expect(jane.labels[1].name).to eql('blue')
96
96
  end
97
97
 
98
+ it 'loads children and its parents via wrap' do
99
+ posts = repo.posts.wrap_parent(author: repo.users)
100
+
101
+ label = repo.labels.combine(many: { posts: posts }).first
102
+
103
+ expect(label.name).to eql('red')
104
+ expect(label.posts.size).to be(1)
105
+ expect(label.posts[0].title).to eql('Hello From Jane')
106
+ expect(label.posts[0].author.name).to eql('Jane')
107
+ end
108
+
98
109
  it 'loads a parent via custom fks' do
99
110
  post = repo.posts.combine(:author).where(title: 'Hello From Jane').one
100
111
 
data/spec/shared/repo.rb CHANGED
@@ -53,7 +53,7 @@ RSpec.shared_context('repo') do
53
53
  end
54
54
 
55
55
  def task_with_user
56
- tasks.find(id: 2).combine_parents(one: users)
56
+ tasks.find(tasks[:id].qualified => 2).wrap_parent(user: users)
57
57
  end
58
58
 
59
59
  def task_with_owner
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom-repository
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta1
4
+ version: 1.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-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rom