dry-mutations 1.0.0 → 1.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
  SHA1:
3
- metadata.gz: 23228f617c8162feb245848da2e562f4b9425bc7
4
- data.tar.gz: 40dc518c5051e58a87950020bccdaf0de17b7dd9
3
+ metadata.gz: 25dba4781a90bcb4441444f72940618ee5cfedac
4
+ data.tar.gz: 44ee6fb881a76e12e503933602d696b1169a3527
5
5
  SHA512:
6
- metadata.gz: 72fed50dd92a78813505cb95db253999860513d8253f0c5a568fa7dba370920c7cc8439b6ebba3a58473bf7c03ffb727481f84802e090029c8b0da93621d1e85
7
- data.tar.gz: b91a085cdc2d0a279d527734c3b55e632cda6722cacc898e0d213c3612182f8800ff7256ffe6b1be0debd2103381301278630755d6d6f219680cc7a17f611750
6
+ metadata.gz: cbb1fce1ab811cc3bfa2384569f1a2d9e245f15bedc29571a8757640a9d81befd360506f2f49a1544caedda3ef8baaa4e0d1dc75edbd7750f98ffa57a22f6369
7
+ data.tar.gz: a141667b23e85eb60549dd6623ca7d80918979e5ddb67fbf7752fbb844eacf81d1c61856ab1bf56e5e35778cb50bfd7afe86c27489f1847e00da3c519552dd6c
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dry-mutations (1.0.0)
4
+ dry-mutations (1.1.0)
5
5
  activesupport (>= 3.2, < 5)
6
- dry-transaction (~> 0.9)
6
+ dry-transaction (~> 0.9, < 0.10)
7
7
  dry-validation (~> 0.10)
8
8
  hashie (~> 3)
9
9
  mutations (~> 0.8)
@@ -32,12 +32,12 @@ GEM
32
32
  concurrent-ruby (1.0.5)
33
33
  diff-lcs (1.2.5)
34
34
  docile (1.1.5)
35
- dry-configurable (0.6.1)
35
+ dry-configurable (0.7.0)
36
36
  concurrent-ruby (~> 1.0)
37
37
  dry-container (0.6.0)
38
38
  concurrent-ruby (~> 1.0)
39
39
  dry-configurable (~> 0.1, >= 0.1.3)
40
- dry-core (0.2.4)
40
+ dry-core (0.3.1)
41
41
  concurrent-ruby (~> 1.0)
42
42
  dry-equalizer (0.2.0)
43
43
  dry-logic (0.4.1)
@@ -45,14 +45,15 @@ GEM
45
45
  dry-core (~> 0.2)
46
46
  dry-equalizer (~> 0.2)
47
47
  dry-matcher (0.6.0)
48
- dry-monads (0.2.1)
48
+ dry-monads (0.3.1)
49
+ dry-core
49
50
  dry-equalizer
50
51
  dry-transaction (0.9.0)
51
52
  dry-container (>= 0.2.8)
52
53
  dry-matcher (>= 0.5.0)
53
54
  dry-monads (>= 0.0.1)
54
55
  wisper (>= 1.6.0)
55
- dry-types (0.9.4)
56
+ dry-types (0.10.3)
56
57
  concurrent-ruby (~> 1.0)
57
58
  dry-configurable (~> 0.1)
58
59
  dry-container (~> 0.3)
@@ -60,7 +61,7 @@ GEM
60
61
  dry-equalizer (~> 0.2)
61
62
  dry-logic (~> 0.4, >= 0.4.0)
62
63
  inflecto (~> 0.0.0, >= 0.0.2)
63
- dry-validation (0.10.5)
64
+ dry-validation (0.10.7)
64
65
  concurrent-ruby (~> 1.0)
65
66
  dry-configurable (~> 0.1, >= 0.1.3)
66
67
  dry-core (~> 0.2, >= 0.2.1)
@@ -103,7 +104,7 @@ GEM
103
104
  thread_safe (0.3.6)
104
105
  tzinfo (1.2.3)
105
106
  thread_safe (~> 0.1)
106
- wisper (1.6.1)
107
+ wisper (2.0.0)
107
108
 
108
109
  PLATFORMS
109
110
  ruby
data/README.md CHANGED
@@ -348,6 +348,9 @@ def validate # input ≡ { date: nil }
348
348
  end
349
349
  ```
350
350
 
351
+ #### 1.1.0
352
+ More handy `chain`s, better `dry-rb` integration, improvements.
353
+
351
354
  #### 0.99.0
352
355
  Support for `default:` guard. 99%-compatibility with `mutations`
353
356
 
@@ -39,5 +39,5 @@ Gem::Specification.new do |spec|
39
39
  spec.add_dependency 'hashie', '~> 3'
40
40
 
41
41
  spec.add_dependency 'dry-validation', '~> 0.10'
42
- spec.add_dependency 'dry-transaction', '~> 0.9'
42
+ spec.add_dependency 'dry-transaction', '~> 0.9', '< 0.10'
43
43
  end
@@ -35,11 +35,11 @@ module Dry
35
35
  attr_reader :validation
36
36
 
37
37
  def initialize(*args)
38
- @raw_inputs = defaults.merge Utils.RawInputs(*args)
39
-
38
+ @raw_inputs = defaults.merge(Utils.RawInputs(*args))
40
39
  @validation_result = discard_empty!
40
+ @inputs = Utils.Hash @validation_result.output
41
41
 
42
- @inputs = fix_accessors Utils.Hash @validation_result.output
42
+ fix_accessors!
43
43
 
44
44
  # dry: {:name=>["size cannot be greater than 10"],
45
45
  # :properties=>{:first_arg=>["must be a string", "is in invalid format"]},
@@ -99,6 +99,7 @@ module Dry
99
99
  super
100
100
  rescue => e
101
101
  add_error(:♻, :runtime_exception, e.message)
102
+ raise e
102
103
  end
103
104
 
104
105
  def add_error(key, kind, message = nil, dry_message = nil)
@@ -110,7 +111,7 @@ module Dry
110
111
  # path=[:maturity_set, :maturity_days_set, :days],
111
112
  # text=\"must be an integer\",
112
113
  # options={:args=>[], :rule=>:days, :each=>false}>"
113
- dry_message ||= ::Dry::Validation::Message.new(kind, *path.map(&:to_sym), message, rule: :♻)
114
+ dry_message ||= ::Dry::Validation::Message.new(kind, key, message, rule: :♻)
114
115
  atom = Errors::ErrorAtom.new(key, kind, dry_message, message: message)
115
116
 
116
117
  last = path.pop
@@ -169,8 +170,8 @@ module Dry
169
170
  )
170
171
  end
171
172
 
172
- def fix_accessors hash
173
- hash.each do |method, _|
173
+ def fix_accessors!
174
+ schema.rules.keys.each do |method|
174
175
  next if respond_to?(name = method)
175
176
 
176
177
  singleton_class.tap do |c|
@@ -1,12 +1,14 @@
1
1
  module Dry
2
2
  module Mutations
3
3
  module Transactions # :nodoc:
4
+ # rubocop:disable Style/MultilineTernaryOperator
4
5
  Container = lambda do |whatever|
5
6
  return ->(*input) { input } unless whatever
6
7
  whatever.respond_to?(:call) ? whatever : Utils.Constant(whatever).tap do |p|
7
8
  fail ArgumentError, "The argument must respond to :call, though #{whatever.inspect} passed." unless p.respond_to? :call
8
9
  end
9
10
  end
11
+ # rubocop:enable Style/MultilineTernaryOperator
10
12
  end
11
13
  end
12
14
  end
@@ -7,39 +7,47 @@ module Dry
7
7
  # step :validate
8
8
  # step :persist
9
9
  # end
10
+
10
11
  module DSL # :nodoc:
11
12
  include Dry::Monads::Either::Mixin
12
13
 
14
+ # rubocop:disable Style/MultilineIfModifier
13
15
  def self.extended base
14
16
  fail Errors::TypeError.new("Extended class [#{base}] should not respond to :call, it is defined by this extension.") if base.respond_to?(:call)
15
- base.send :define_method, :initialize do |input|
16
- @input = input
17
+ base.send :define_method, :initialize do |*input|
18
+ @input = Utils.RawInputs(*input)
17
19
  end unless base.instance_methods(false).include?(:initialize)
18
- %i(run run!).each do |meth|
20
+ %i(call run run!).each do |meth|
19
21
  base.send :define_method, meth do
20
22
  base.public_send(meth, @input)
21
23
  end unless base.instance_methods(false).include?(meth)
22
24
  end
23
25
  end
26
+ # rubocop:enable Style/MultilineIfModifier
24
27
 
25
28
  def chain **params
26
29
  return enum_for(:chain) unless block_given? # FIXME: Needed? Works? Remove?
27
30
 
31
+ # rubocop:disable Style/VariableNumber
28
32
  λ = Proc.new
29
33
 
30
- @transaction = ::Dry.Transaction(container: ::Dry::Mutations::Transactions::Container, step_adapters: StepAdapters) do
34
+ @transaction = ::Dry.Transaction(
35
+ container: ::Dry::Mutations::Transactions::Container,
36
+ step_adapters: StepAdapters
37
+ ) do
31
38
  instance_eval(&λ)
32
39
  end.tap do |transaction|
33
- singleton_class.send :define_method, :call do |input|
34
- transaction.(input)
40
+ singleton_class.send :define_method, :call do |*input|
41
+ transaction.(Utils.RawInputs(*input))
35
42
  end
36
- singleton_class.send :define_method, :run do |input|
37
- ::Dry::Mutations::Extensions::Outcome(transaction.(input))
43
+ singleton_class.send :define_method, :run do |*input|
44
+ ::Dry::Mutations::Extensions::Outcome(transaction.(Utils.RawInputs(*input)))
38
45
  end
39
- singleton_class.send :define_method, :run! do |input|
40
- ::Dry::Mutations::Extensions::Outcome!(transaction.(input))
46
+ singleton_class.send :define_method, :run! do |*input|
47
+ ::Dry::Mutations::Extensions::Outcome!(transaction.(Utils.RawInputs(*input)))
41
48
  end
42
49
  end
50
+ # rubocop:enable Style/VariableNumber
43
51
  end
44
52
  end
45
53
  end
@@ -17,7 +17,7 @@ module Dry
17
17
  end
18
18
 
19
19
  def call(step, *args, input)
20
- step.operation.(input, *args)
20
+ step.operation.(input, *args, &step.block)
21
21
  end
22
22
  end
23
23
 
@@ -0,0 +1,22 @@
1
+ module Dry
2
+ module Mutations
3
+ module Transactions # :nodoc:
4
+ # http://dry-rb.org/gems/dry-transaction/custom-step-adapters/
5
+ # step adapters must provide a single `#call(step, *args, input)` method,
6
+ # which should return the step’s result wrapped in an `Either` object.
7
+ # This one is a wrapper for neted chains
8
+ class Chain < StepAdapters::Move
9
+ def call(step, *args, input)
10
+ if step.block
11
+ Class.new do
12
+ extend ::Dry::Mutations::Transactions::DSL
13
+ chain(&step.block)
14
+ end.(input, *args)
15
+ else
16
+ super
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,4 +1,7 @@
1
+ # rubocop:disable Style/FileName
1
2
  require 'dry-types'
3
+ # rubocop:enable Style/FileName
4
+
2
5
  module Dry
3
6
  module Mutations
4
7
  module Utils # :nodoc:
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Mutations
3
- VERSION = '1.0.0'.freeze
3
+ VERSION = '1.1.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-mutations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Matiushkin
@@ -183,6 +183,9 @@ dependencies:
183
183
  - - "~>"
184
184
  - !ruby/object:Gem::Version
185
185
  version: '0.9'
186
+ - - "<"
187
+ - !ruby/object:Gem::Version
188
+ version: '0.10'
186
189
  type: :runtime
187
190
  prerelease: false
188
191
  version_requirements: !ruby/object:Gem::Requirement
@@ -190,6 +193,9 @@ dependencies:
190
193
  - - "~>"
191
194
  - !ruby/object:Gem::Version
192
195
  version: '0.9'
196
+ - - "<"
197
+ - !ruby/object:Gem::Version
198
+ version: '0.10'
193
199
  description: |2
194
200
  Mutations gem interface implemented with `dry-rb`’s validation schemas.
195
201
  email:
@@ -240,6 +246,7 @@ files:
240
246
  - lib/dry/mutations/transactions/container.rb
241
247
  - lib/dry/mutations/transactions/dsl.rb
242
248
  - lib/dry/mutations/transactions/step_adapters.rb
249
+ - lib/dry/mutations/transactions/step_adapters/chain.rb
243
250
  - lib/dry/mutations/transactions/step_adapters/mutate.rb
244
251
  - lib/dry/mutations/transactions/step_adapters/tranquilo.rb
245
252
  - lib/dry/mutations/transactions/step_adapters/transform.rb