rom-changeset 5.0.1 → 5.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5113fef2e602597e83643a826267f5929db3eeeeaa7b01e93c595347dbe00a19
4
- data.tar.gz: 958d4b0aa87c25e9c6d16f545fa76479ac87189c51734706b41760409faccb7f
3
+ metadata.gz: fee212ac172f99e26d51cc114d9ad7578ffaf2666e163c90f65d1c5d7555918f
4
+ data.tar.gz: eceab3b4e8a8413886f7b18b58895004a2ad9d0adca82daf33d6b9a2a484cf93
5
5
  SHA512:
6
- metadata.gz: eb9c9c67ee856f5c1f0b54851b51e5bcb848a523ef02be41cd9c59aed2466cd9ca555794468a59c5a57ad649cb4f4c424ad81832a456f555d1273c008fb1c640
7
- data.tar.gz: 549ce4306027970c32ed7f620d80c1fd94d71771f09543966dc1fc63ca4a25ac88dd53cfbd8477fd66118d6f01582f2d261dee5dc0952b9a89b9d4fd4d1165a7
6
+ metadata.gz: 2d494ccaaa3e744228dcc3326fb6d2b626d184f37288b2f2c844b3ef5676369bc1cd0b0d71b824420bca6c3ef46938bbc8479b4cf5e44cdb5fdaacb90875826c
7
+ data.tar.gz: 95c7c2664964b7180933a47a8cf0d1f168e18ddec7f76d826e3638d16bfec8e63b8a6f474143cff4638da5951d3074feae0457bbefc81ee3f4e88a76af6699fe
@@ -18,8 +18,6 @@ module ROM
18
18
  #
19
19
  # @abstract
20
20
  class Changeset
21
- DEFAULT_COMMAND_OPTS = { mapper: false }.freeze
22
-
23
21
  extend Initializer
24
22
  extend Dry::Core::Cache
25
23
  extend Dry::Core::ClassAttributes
@@ -37,6 +35,32 @@ module ROM
37
35
  # @return [Symbol]
38
36
  defines :command_type
39
37
 
38
+ # @!method self.command_options
39
+ # Get or set command options
40
+ #
41
+ # @overload command_options
42
+ # Return configured command_options
43
+ # @return [Hash,nil]
44
+ #
45
+ # @overload command_options(**options)
46
+ # Set command options
47
+ # @param options [Hash] The command options
48
+ # @return [Hash]
49
+ defines :command_options
50
+
51
+ # @!method self.command_plugins
52
+ # Get or set command plugins options
53
+ #
54
+ # @overload command_plugins
55
+ # Return configured command_plugins
56
+ # @return [Hash,nil]
57
+ #
58
+ # @overload command_plugins(**options)
59
+ # Set command plugin options
60
+ # @param options [Hash] The command plugin options
61
+ # @return [Hash]
62
+ defines :command_plugins
63
+
40
64
  # @!method self.relation
41
65
  # Get or set changeset relation identifier
42
66
  #
@@ -58,6 +82,20 @@ module ROM
58
82
  # @return [Symbol] a custom command identifier
59
83
  option :command_type, default: -> { self.class.command_type }
60
84
 
85
+ # @!attribute [r] command_options
86
+ # @return [Hash] Configured options for the command
87
+ option :command_options, default: -> { self.class.command_options }
88
+
89
+ # @!attribute [r] command_plugins
90
+ # @return [Hash] Configured plugin options for the command
91
+ option :command_plugins, default: -> { self.class.command_plugins }
92
+
93
+ # Set the default command options
94
+ command_options(mapper: false)
95
+
96
+ # Set the default command plugin options
97
+ command_plugins(EMPTY_HASH)
98
+
61
99
  # Create a changeset class preconfigured for a specific relation
62
100
  #
63
101
  # @example
@@ -73,6 +111,13 @@ module ROM
73
111
  }
74
112
  end
75
113
 
114
+ # Enable a plugin for the changeset
115
+ #
116
+ # @api public
117
+ def self.use(plugin, options = EMPTY_HASH)
118
+ ROM.plugin_registry[:changeset].fetch(plugin).apply_to(self, options)
119
+ end
120
+
76
121
  # Return a new changeset with provided relation
77
122
  #
78
123
  # New options can be provided too
@@ -116,7 +161,16 @@ module ROM
116
161
  #
117
162
  # @api private
118
163
  def command
119
- relation.command(command_type, DEFAULT_COMMAND_OPTS)
164
+ relation.command(command_type, command_compiler_options)
165
+ end
166
+
167
+ # Return configured command compiler options
168
+ #
169
+ # @return [Hash]
170
+ #
171
+ # @api private
172
+ def command_compiler_options
173
+ command_options.merge(use: command_plugins.keys, plugins_options: command_plugins)
120
174
  end
121
175
  end
122
176
  end
@@ -127,3 +181,7 @@ require 'rom/changeset/associated'
127
181
  require 'rom/changeset/create'
128
182
  require 'rom/changeset/update'
129
183
  require 'rom/changeset/delete'
184
+
185
+ require 'rom/plugins'
186
+
187
+ ROM::Plugins.register(:changeset, adapter: false)
@@ -234,11 +234,6 @@ module ROM
234
234
  __data__.is_a?(Array) ? :many : :one
235
235
  end
236
236
 
237
- # @api public
238
- def command
239
- relation.command(command_type, DEFAULT_COMMAND_OPTS.merge(result: result))
240
- end
241
-
242
237
  # Return string representation of the changeset
243
238
  #
244
239
  # @return [String]
@@ -248,6 +243,11 @@ module ROM
248
243
  %(#<#{self.class} relation=#{relation.name.inspect} data=#{__data__}>)
249
244
  end
250
245
 
246
+ # @api private
247
+ def command_compiler_options
248
+ super.merge(result: result)
249
+ end
250
+
251
251
  # Data transformation pipe
252
252
  #
253
253
  # @return [Changeset::Pipe]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ROM
4
4
  class Changeset
5
- VERSION = '5.0.1'
5
+ VERSION = '5.1.0'
6
6
  end
7
7
  end
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.0.1
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-01 00:00:00.000000000 Z
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-core
@@ -16,34 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.3'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 0.3.1
19
+ version: '0.4'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0.3'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 0.3.1
26
+ version: '0.4'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rom-core
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '5.0'
33
+ version: '5.1'
40
34
  type: :runtime
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '5.0'
40
+ version: '5.1'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: transproc
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -51,6 +45,9 @@ dependencies:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '1.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.1.0
54
51
  type: :runtime
55
52
  prerelease: false
56
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,6 +55,9 @@ dependencies:
58
55
  - - "~>"
59
56
  - !ruby/object:Gem::Version
60
57
  version: '1.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.1.0
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rake
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +109,11 @@ files:
109
109
  homepage: http://rom-rb.org
110
110
  licenses:
111
111
  - MIT
112
- metadata: {}
112
+ metadata:
113
+ source_code_uri: https://github.com/rom-rb/rom/tree/master/changeset
114
+ documentation_uri: https://api.rom-rb.org/rom/
115
+ mailing_list_uri: https://discourse.rom-rb.org/
116
+ bug_tracker_uri: https://github.com/rom-rb/rom/issues
113
117
  post_install_message:
114
118
  rdoc_options: []
115
119
  require_paths: