rom-repository 1.0.0.rc1 → 1.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/lib/rom/repository/changeset.rb +1 -4
- data/lib/rom/repository/changeset/create.rb +2 -0
- data/lib/rom/repository/changeset/stateful.rb +3 -3
- data/lib/rom/repository/changeset/update.rb +3 -1
- data/lib/rom/repository/class_interface.rb +5 -4
- data/lib/rom/repository/command_compiler.rb +22 -2
- data/lib/rom/repository/relation_proxy.rb +4 -2
- data/lib/rom/repository/version.rb +1 -1
- data/spec/integration/command_macros_spec.rb +13 -0
- data/spec/integration/command_spec.rb +10 -0
- data/spec/shared/relations.rb +1 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/unit/relation_proxy_spec.rb +6 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abd8ee5d8b4132b20ab01c4fc4ee586c26b0e7ac
|
4
|
+
data.tar.gz: c4f4b25f08b77773c33b585e41cf20b7725f324f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb3fe13af29c34580949161270134dfcc53a80fe083948bde31c0eb8126b710c962df8b76a5d0fb371f5e5ae776eafc7df036dc151038220af812036d713c72b
|
7
|
+
data.tar.gz: 788fa703d7e283afbf330059ce7466b8882ed907ecc8e8ca65ff90a297f0f710167afe4e13d7d7e14d27b9fe5697ee1d3b28bc34c5b51f2443092b35b3d29e2a
|
data/CHANGELOG.md
CHANGED
@@ -24,6 +24,7 @@
|
|
24
24
|
### Fixed
|
25
25
|
|
26
26
|
* FKs are always included in auto-generated structs used in aggregates (solnic)
|
27
|
+
* Calling undefined methods on repo relations raises a nicer error (solnic)
|
27
28
|
|
28
29
|
[Compare v0.3.1...v1.0.0](https://github.com/rom-rb/rom-repository/compare/v0.3.1...v1.0.0)
|
29
30
|
|
@@ -9,11 +9,8 @@ module ROM
|
|
9
9
|
# If you inherit from this class you need to configure additional settings
|
10
10
|
#
|
11
11
|
# @example define a custom changeset using :upsert command
|
12
|
-
#
|
13
12
|
# class NewTag < ROM::Changeset[:tags]
|
14
|
-
#
|
15
|
-
# :upsert
|
16
|
-
# end
|
13
|
+
# command_type :upsert
|
17
14
|
# end
|
18
15
|
#
|
19
16
|
# @abstract
|
@@ -52,7 +52,9 @@ module ROM
|
|
52
52
|
# end
|
53
53
|
# end
|
54
54
|
#
|
55
|
-
# @return [Array<Pipe
|
55
|
+
# @return [Array<Pipe>, Transproc::Function>]
|
56
|
+
#
|
57
|
+
# @see https://github.com/solnic/transproc Transproc
|
56
58
|
#
|
57
59
|
# @api public
|
58
60
|
def self.map(&block)
|
@@ -100,8 +102,6 @@ module ROM
|
|
100
102
|
# @example
|
101
103
|
# changeset.map { |tuple| tuple.merge(created_at: Time.now) }
|
102
104
|
#
|
103
|
-
# @param [Array<Symbol>] steps A list of mapping steps
|
104
|
-
#
|
105
105
|
# @overload map(*steps, &block)
|
106
106
|
# Apply mapping using built-in transformations and a custom block
|
107
107
|
#
|
@@ -9,6 +9,8 @@ module ROM
|
|
9
9
|
# you need to implement it yourself in your relations if you want to
|
10
10
|
# use Update changesets.
|
11
11
|
#
|
12
|
+
# @see Changeset::Stateful
|
13
|
+
#
|
12
14
|
# @api public
|
13
15
|
class Update < Stateful
|
14
16
|
command_type :update
|
@@ -65,7 +67,7 @@ module ROM
|
|
65
67
|
|
66
68
|
# Calculate the diff between the original and changeset data
|
67
69
|
#
|
68
|
-
# @return [Hash
|
70
|
+
# @return [Hash]
|
69
71
|
#
|
70
72
|
# @api public
|
71
73
|
def diff
|
@@ -112,11 +112,12 @@ module ROM
|
|
112
112
|
|
113
113
|
# @api private
|
114
114
|
def define_command_method(type, **opts)
|
115
|
-
define_method(type) do
|
116
|
-
if input.respond_to?(:commit)
|
117
|
-
|
115
|
+
define_method(type) do |*input|
|
116
|
+
if input.size == 1 && input[0].respond_to?(:commit)
|
117
|
+
changeset = input[0]
|
118
|
+
map_tuple(changeset.relation, changeset.commit)
|
118
119
|
else
|
119
|
-
command(type => self.class.root, **opts).call(input)
|
120
|
+
command(type => self.class.root, **opts).call(*input)
|
120
121
|
end
|
121
122
|
end
|
122
123
|
end
|
@@ -117,13 +117,33 @@ module ROM
|
|
117
117
|
if type
|
118
118
|
register_command(name, type, meta, parent_relation)
|
119
119
|
|
120
|
-
|
120
|
+
default_mapping =
|
121
121
|
if meta[:combine_type] == :many
|
122
122
|
name
|
123
|
-
else
|
123
|
+
else meta[:combine_type] == :one
|
124
124
|
{ Dry::Core::Inflector.singularize(name).to_sym => name }
|
125
125
|
end
|
126
126
|
|
127
|
+
mapping =
|
128
|
+
if parent_relation
|
129
|
+
associations = container.relations[parent_relation].associations
|
130
|
+
|
131
|
+
assoc =
|
132
|
+
if associations.key?(meta[:combine_name])
|
133
|
+
associations[meta[:combine_name]]
|
134
|
+
elsif associations.key?(name)
|
135
|
+
associations[name]
|
136
|
+
end
|
137
|
+
|
138
|
+
if assoc
|
139
|
+
{ assoc.target.key => assoc.target.dataset }
|
140
|
+
else
|
141
|
+
default_mapping
|
142
|
+
end
|
143
|
+
else
|
144
|
+
default_mapping
|
145
|
+
end
|
146
|
+
|
127
147
|
if other.size > 0
|
128
148
|
[mapping, [type, other]]
|
129
149
|
else
|
@@ -64,7 +64,7 @@ module ROM
|
|
64
64
|
# Map tuples using registered mappers
|
65
65
|
#
|
66
66
|
# @example
|
67
|
-
# users.
|
67
|
+
# users.map_with(:my_mapper, :my_other_mapper)
|
68
68
|
#
|
69
69
|
# @param [Array<Symbol>] mappers A list of mapper identifiers
|
70
70
|
#
|
@@ -74,6 +74,8 @@ module ROM
|
|
74
74
|
def map_with(*names)
|
75
75
|
if names.size == 1 && names[0].is_a?(Class)
|
76
76
|
with(meta: meta.merge(model: names[0]))
|
77
|
+
elsif names.size > 1 && names.any? { |name| name.is_a?(Class) }
|
78
|
+
raise ArgumentError, 'using custom mappers and a model is not supported'
|
77
79
|
else
|
78
80
|
names.reduce(self) { |a, e| a >> relation.mappers[e] }
|
79
81
|
end
|
@@ -225,7 +227,7 @@ module ROM
|
|
225
227
|
result
|
226
228
|
end
|
227
229
|
else
|
228
|
-
|
230
|
+
raise NoMethodError, "undefined method `#{meth}' for #{relation.class.name}"
|
229
231
|
end
|
230
232
|
end
|
231
233
|
end
|
@@ -58,6 +58,19 @@ RSpec.describe ROM::Repository, '.command' do
|
|
58
58
|
expect(updated_user.name).to eql('Jane Doe')
|
59
59
|
end
|
60
60
|
|
61
|
+
it 'allows to configure :delete command without args' do
|
62
|
+
repo = Class.new(ROM::Repository[:users]) do
|
63
|
+
commands :delete
|
64
|
+
end.new(rom)
|
65
|
+
|
66
|
+
repo.users.insert(name: 'Jane')
|
67
|
+
repo.users.insert(name: 'John')
|
68
|
+
|
69
|
+
repo.delete
|
70
|
+
|
71
|
+
expect(repo.users.count).to be_zero
|
72
|
+
end
|
73
|
+
|
61
74
|
it 'allows defining a single command with multiple views' do
|
62
75
|
repo = Class.new(ROM::Repository[:users]) do
|
63
76
|
commands :create, update: [:by_pk, :by_name]
|
@@ -92,6 +92,16 @@ RSpec.describe ROM::Repository, '#command' do
|
|
92
92
|
expect(user.tasks.first.title).to eql('Task one')
|
93
93
|
end
|
94
94
|
|
95
|
+
it 'builds Create command for a relation graph with one-to-many with aliased association' do
|
96
|
+
create_user = repo.command(:create, repo.users.combine(:aliased_posts))
|
97
|
+
|
98
|
+
user = create_user.call(name: 'Jane Doe', aliased_posts: [{ title: 'Post one' }, { title: 'Post two' }])
|
99
|
+
|
100
|
+
expect(user.id).to_not be(nil)
|
101
|
+
expect(user.name).to eql('Jane Doe')
|
102
|
+
expect(user.aliased_posts.size).to be(2)
|
103
|
+
end
|
104
|
+
|
95
105
|
it 'builds Create command for a deeply nested graph with one-to-many' do
|
96
106
|
create_user = repo.command(
|
97
107
|
:create,
|
data/spec/shared/relations.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -33,6 +33,13 @@ end
|
|
33
33
|
require 'dry/core/deprecations'
|
34
34
|
Dry::Core::Deprecations.set_logger!(root.join('../log/deprecations.log'))
|
35
35
|
|
36
|
+
# Make inference errors quiet
|
37
|
+
class ROM::SQL::Schema::Inferrer
|
38
|
+
def self.on_error(*args)
|
39
|
+
# shush
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
36
43
|
# Namespace holding all objects created during specs
|
37
44
|
module Test
|
38
45
|
def self.remove_constants
|
@@ -61,6 +61,11 @@ RSpec.describe 'loading proxy' do
|
|
61
61
|
[{ id: 1, name: 'Jane' }, {id: 2, name: 'Joe' }]
|
62
62
|
)
|
63
63
|
end
|
64
|
+
|
65
|
+
it 'raises error when custom mapper is used with a model class' do
|
66
|
+
expect { users.map_with(:name_list, Class.new) }.
|
67
|
+
to raise_error(ArgumentError, 'using custom mappers and a model is not supported')
|
68
|
+
end
|
64
69
|
end
|
65
70
|
|
66
71
|
context 'setting custom model type' do
|
@@ -182,7 +187,7 @@ RSpec.describe 'loading proxy' do
|
|
182
187
|
end
|
183
188
|
|
184
189
|
it 'raises when method is missing' do
|
185
|
-
expect { users.not_here }.to raise_error(NoMethodError,
|
190
|
+
expect { users.not_here }.to raise_error(NoMethodError, "undefined method `not_here' for ROM::Relation[Users]")
|
186
191
|
end
|
187
192
|
end
|
188
193
|
end
|
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.
|
4
|
+
version: 1.0.0.rc2
|
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-
|
11
|
+
date: 2017-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rom
|