rom-changeset 5.1.2 → 5.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rom/changeset.rb +5 -5
- data/lib/rom/changeset/extensions/relation.rb +3 -1
- data/lib/rom/changeset/pipe.rb +37 -43
- data/lib/rom/changeset/pipe_registry.rb +27 -0
- data/lib/rom/changeset/stateful.rb +10 -8
- data/lib/rom/changeset/update.rb +1 -1
- data/lib/rom/changeset/version.rb +1 -1
- metadata +6 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5a4ea75bcd9a214497927450d214530d5a3463e2079ae352ec24438f9c5c8f1
|
4
|
+
data.tar.gz: 02d7fdb3a5d700fd800d8170dfa3dee15a898392131f3a4ffff911c7a0e220b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b913372527a053b698935fc60d17b3e3093c49e2a152f437d699dfbfce78770411f89d968f7e47bc3cba771f313aa3a458a4c9e6d1706278cd3de9e6cef092b
|
7
|
+
data.tar.gz: 82701e7bb81506e39207d999b986d544173b9251de886a1c0f4d0d6ba2e6b903ff97bf9d621eb149b296c7d04a5964b39ad1a363993630e1a809a0c54d64c6e8
|
data/lib/rom/changeset.rb
CHANGED
@@ -114,8 +114,8 @@ module ROM
|
|
114
114
|
# Enable a plugin for the changeset
|
115
115
|
#
|
116
116
|
# @api public
|
117
|
-
def self.use(plugin, options
|
118
|
-
ROM.plugin_registry[:changeset].fetch(plugin).apply_to(self, options)
|
117
|
+
def self.use(plugin, **options)
|
118
|
+
ROM.plugin_registry[:changeset].fetch(plugin).apply_to(self, **options)
|
119
119
|
end
|
120
120
|
|
121
121
|
# Return a new changeset with provided relation
|
@@ -128,8 +128,8 @@ module ROM
|
|
128
128
|
# @return [Changeset]
|
129
129
|
#
|
130
130
|
# @api public
|
131
|
-
def new(relation, new_options
|
132
|
-
self.class.new(relation,
|
131
|
+
def new(relation, **new_options)
|
132
|
+
self.class.new(relation, **options, **new_options)
|
133
133
|
end
|
134
134
|
|
135
135
|
# Persist changeset
|
@@ -161,7 +161,7 @@ module ROM
|
|
161
161
|
#
|
162
162
|
# @api private
|
163
163
|
def command
|
164
|
-
relation.command(command_type, command_compiler_options)
|
164
|
+
relation.command(command_type, **command_compiler_options)
|
165
165
|
end
|
166
166
|
|
167
167
|
# Return configured command compiler options
|
data/lib/rom/changeset/pipe.rb
CHANGED
@@ -1,61 +1,63 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'transproc/all'
|
4
|
-
require 'transproc/registry'
|
5
3
|
require 'transproc/transformer'
|
6
4
|
|
5
|
+
require 'rom/changeset/pipe_registry'
|
6
|
+
|
7
7
|
module ROM
|
8
8
|
class Changeset
|
9
|
-
# Transproc Registry useful for pipe
|
10
|
-
#
|
11
|
-
# @api private
|
12
|
-
module PipeRegistry
|
13
|
-
extend Transproc::Registry
|
14
|
-
|
15
|
-
import Transproc::HashTransformations
|
16
|
-
|
17
|
-
def self.add_timestamps(data)
|
18
|
-
now = Time.now
|
19
|
-
Hash(created_at: now, updated_at: now).merge(data)
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.touch(data)
|
23
|
-
Hash(updated_at: Time.now).merge(data)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
9
|
# Composable data transformation pipe used by default in changesets
|
28
10
|
#
|
29
11
|
# @api private
|
30
12
|
class Pipe < Transproc::Transformer[PipeRegistry]
|
31
13
|
extend Initializer
|
32
14
|
|
33
|
-
|
15
|
+
define!(&:identity)
|
16
|
+
|
17
|
+
param :processor, optional: true
|
18
|
+
|
34
19
|
option :use_for_diff, optional: true, default: -> { true }
|
35
|
-
option :diff_processor, default: -> {
|
20
|
+
option :diff_processor, default: -> { self[processor] }
|
36
21
|
|
37
|
-
def self.
|
38
|
-
|
22
|
+
def self.new(*args, **opts)
|
23
|
+
if args.empty?
|
24
|
+
initialize(**opts)
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.initialize(**opts)
|
31
|
+
transformer = allocate
|
32
|
+
transformer.__send__(:initialize, dsl.(transformer), **opts)
|
33
|
+
transformer
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.[](name_or_proc)
|
37
|
+
container[name_or_proc]
|
39
38
|
end
|
40
39
|
|
41
|
-
def [](
|
42
|
-
self.class[
|
40
|
+
def [](*args)
|
41
|
+
self.class[*args]
|
43
42
|
end
|
44
43
|
|
45
44
|
def bind(context)
|
46
45
|
if processor.is_a?(Proc)
|
47
|
-
self.class
|
46
|
+
new(self.class[-> *args { context.instance_exec(*args, &processor) }])
|
48
47
|
else
|
49
48
|
self
|
50
49
|
end
|
51
50
|
end
|
52
51
|
|
53
|
-
def compose(other, for_diff: other.is_a?(
|
54
|
-
new_proc = processor
|
52
|
+
def compose(other, for_diff: other.is_a?(self.class) ? other.use_for_diff : false)
|
53
|
+
new_proc = processor >> other
|
55
54
|
|
56
55
|
if for_diff
|
57
|
-
diff_proc = diff_processor
|
58
|
-
|
56
|
+
diff_proc = diff_processor >> (
|
57
|
+
other.is_a?(self.class) ? other.diff_processor : other
|
58
|
+
)
|
59
|
+
|
60
|
+
new(new_proc, use_for_diff: true, diff_processor: diff_proc)
|
59
61
|
else
|
60
62
|
new(new_proc)
|
61
63
|
end
|
@@ -63,23 +65,15 @@ module ROM
|
|
63
65
|
alias_method :>>, :compose
|
64
66
|
|
65
67
|
def call(data)
|
66
|
-
|
67
|
-
processor.call(data)
|
68
|
-
else
|
69
|
-
data
|
70
|
-
end
|
68
|
+
processor.call(data)
|
71
69
|
end
|
72
70
|
|
73
71
|
def for_diff(data)
|
74
|
-
|
75
|
-
diff_processor.call(data)
|
76
|
-
else
|
77
|
-
data
|
78
|
-
end
|
72
|
+
use_for_diff ? diff_processor.call(data) : data
|
79
73
|
end
|
80
74
|
|
81
|
-
def new(processor, opts
|
82
|
-
|
75
|
+
def new(processor, **opts)
|
76
|
+
self.class.new(processor, **options, **opts)
|
83
77
|
end
|
84
78
|
end
|
85
79
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'transproc/all'
|
4
|
+
require 'transproc/registry'
|
5
|
+
|
6
|
+
module ROM
|
7
|
+
class Changeset
|
8
|
+
# Transproc Registry useful for pipe
|
9
|
+
#
|
10
|
+
# @api private
|
11
|
+
module PipeRegistry
|
12
|
+
extend Transproc::Registry
|
13
|
+
|
14
|
+
import Transproc::Coercions
|
15
|
+
import Transproc::HashTransformations
|
16
|
+
|
17
|
+
def self.add_timestamps(data)
|
18
|
+
now = Time.now
|
19
|
+
Hash(created_at: now, updated_at: now).merge(data)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.touch(data)
|
23
|
+
Hash(updated_at: Time.now).merge(data)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -57,11 +57,11 @@ module ROM
|
|
57
57
|
# @see https://github.com/solnic/transproc Transproc
|
58
58
|
#
|
59
59
|
# @api public
|
60
|
-
def self.map(options
|
60
|
+
def self.map(**options, &block)
|
61
61
|
if block.parameters.empty?
|
62
|
-
pipes << Class.new(Pipe
|
62
|
+
pipes << Class.new(Pipe).define!(&block).new(**options)
|
63
63
|
else
|
64
|
-
pipes << Pipe.new(block, options)
|
64
|
+
pipes << Pipe.new(block, **options)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -87,12 +87,13 @@ module ROM
|
|
87
87
|
#
|
88
88
|
# @return [Pipe]
|
89
89
|
def self.default_pipe(context)
|
90
|
-
pipes.
|
90
|
+
!pipes.empty? ? pipes.map { |p| p.bind(context) }.reduce(:>>) : EMPTY_PIPE
|
91
91
|
end
|
92
92
|
|
93
93
|
# @api private
|
94
94
|
def self.inherited(klass)
|
95
95
|
return if klass == ROM::Changeset
|
96
|
+
|
96
97
|
super
|
97
98
|
klass.instance_variable_set(:@__pipes__, pipes.dup)
|
98
99
|
end
|
@@ -149,13 +150,13 @@ module ROM
|
|
149
150
|
# @api public
|
150
151
|
def extend(*steps, **options, &block)
|
151
152
|
if block
|
152
|
-
if steps.
|
153
|
-
extend(*steps, options).extend(options, &block)
|
153
|
+
if !steps.empty?
|
154
|
+
extend(*steps, **options).extend(**options, &block)
|
154
155
|
else
|
155
|
-
with(pipe: pipe.compose(Pipe.new(block).bind(self), options))
|
156
|
+
with(pipe: pipe.compose(Pipe.new(block).bind(self), **options))
|
156
157
|
end
|
157
158
|
else
|
158
|
-
with(pipe: steps.reduce(pipe.with(options)) { |a, e| a.compose(pipe[e], options) })
|
159
|
+
with(pipe: steps.reduce(pipe.with(**options)) { |a, e| a.compose(pipe[e], **options) })
|
159
160
|
end
|
160
161
|
end
|
161
162
|
|
@@ -278,6 +279,7 @@ module ROM
|
|
278
279
|
super
|
279
280
|
end
|
280
281
|
end
|
282
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
281
283
|
end
|
282
284
|
end
|
283
285
|
end
|
data/lib/rom/changeset/update.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rom-changeset
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1
|
4
|
+
version: 5.2.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:
|
11
|
+
date: 2020-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-core
|
@@ -30,20 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '5.
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 5.1.2
|
33
|
+
version: '5.2'
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
38
|
- - "~>"
|
42
39
|
- !ruby/object:Gem::Version
|
43
|
-
version: '5.
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 5.1.2
|
40
|
+
version: '5.2'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: transproc
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +102,7 @@ files:
|
|
108
102
|
- lib/rom/changeset/delete.rb
|
109
103
|
- lib/rom/changeset/extensions/relation.rb
|
110
104
|
- lib/rom/changeset/pipe.rb
|
105
|
+
- lib/rom/changeset/pipe_registry.rb
|
111
106
|
- lib/rom/changeset/stateful.rb
|
112
107
|
- lib/rom/changeset/update.rb
|
113
108
|
- lib/rom/changeset/version.rb
|
@@ -135,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
130
|
- !ruby/object:Gem::Version
|
136
131
|
version: '0'
|
137
132
|
requirements: []
|
138
|
-
rubygems_version: 3.0.
|
133
|
+
rubygems_version: 3.1.0.pre3
|
139
134
|
signing_key:
|
140
135
|
specification_version: 4
|
141
136
|
summary: Changeset abstraction for rom-rb
|