dry-mutations 1.5.0 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ef61504d19fddc6238d0ecfc61a8a61da070075
4
- data.tar.gz: d1edf21a714efcb004083cbd3e8e19e834517c05
3
+ metadata.gz: 03b5e7decfb90e826930fba23b09132cf888b044
4
+ data.tar.gz: f08c0296e1f5fff04ee3beb5d37546582a603baf
5
5
  SHA512:
6
- metadata.gz: e75bc3759db8394d410bf62d0afee3c64f9061bdb81ef4a9ca90190ff2830ba7d7bb98ec98c39db85ee43719fbb62cd6a2a10b3d58e52600b2791273cb0bd5a4
7
- data.tar.gz: e0ff36117ec61ff21a1c26fd247188325b93ecbf2fe0781dec2d8fd39591bbd7d2c1d094609b8b0175bb7dd24a16fe290be4f0802fda9c02d85b6805718189d5
6
+ metadata.gz: dd5b5f254adc9285bfd52ce62422038c8f8f76f3735e431f9a5abd328479700c98c37618040960d29fbd6fdc3aab819342d64c789155a98fb86b0e7a9bbbc87c
7
+ data.tar.gz: 3dd1490a0226e6f2fc70fdb5154adfb16c8181d3ba76eacb58fbbc897df50d7352ed2d98c3b1a7390a8d1c33ad160871a882f2d26c5d3b675a80ee1b1c564f19
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dry-mutations (1.5.0)
4
+ dry-mutations (1.5.1)
5
5
  activesupport (>= 3.2, < 5)
6
6
  dry-transaction (~> 0.9, < 0.10)
7
7
  dry-validation (~> 0.10)
@@ -17,7 +17,10 @@ module Dry
17
17
  end
18
18
 
19
19
  def call(*args)
20
- new(*args).()
20
+ callable = to_proc.(*args)
21
+ outcome = callable.()
22
+ ensure
23
+ ::Dry::Mutations::Utils.extend_outcome outcome, callable.host
21
24
  end
22
25
 
23
26
  def to_proc
@@ -38,6 +41,10 @@ module Dry
38
41
  %i|exceptions_as_errors finalizers call to_proc|.include?(method_name) || super
39
42
  end
40
43
  end)
44
+
45
+ define_method :host do
46
+ base.to_s
47
+ end
41
48
  end
42
49
 
43
50
  attr_reader :validation
@@ -72,6 +79,12 @@ module Dry
72
79
  ### Functional helpers
73
80
  ########################################################################
74
81
 
82
+ def run
83
+ outcome = super
84
+ ensure
85
+ ::Dry::Mutations::Utils.extend_outcome outcome, host
86
+ end
87
+
75
88
  def call
76
89
  run.either
77
90
  end
@@ -91,11 +91,17 @@ module Dry
91
91
  case input
92
92
  when ::Mutations::Outcome then input
93
93
  when ::Dry::Monads::Either::Left
94
- ::Mutations::Outcome.new(false, nil, input.value, nil)
94
+ ::Mutations::Outcome.new(false, nil, input.value, nil).tap do |outcome|
95
+ ::Dry::Mutations::Utils.extend_outcome outcome, input.value.host
96
+ end
95
97
  when ::Dry::Monads::Either::Right
96
- ::Mutations::Outcome.new(true, input.value, nil, nil)
98
+ ::Mutations::Outcome.new(true, input.value, nil, nil).tap do |outcome|
99
+ ::Dry::Mutations::Utils.extend_outcome outcome, input.value.host
100
+ end
97
101
  when ->(inp) { inp.respond_to?(:success?) }
98
- ::Mutations::Outcome.new(input.success?, input.success? && input, input.success? || input, nil)
102
+ ::Mutations::Outcome.new(input.success?, input.success? && input, input.success? || input, nil).tap do |outcome|
103
+ ::Dry::Mutations::Utils.extend_outcome outcome, input.host if input.respond_to?(:host)
104
+ end
99
105
  else fail TypeError.new("Wrong input passed to Outcome(): [#{input.inspect}]")
100
106
  end
101
107
  end
@@ -10,6 +10,14 @@ module Dry
10
10
  name = Utils.Snake(sub, short: true, symbolize: true)
11
11
  StepAdapters.register name, sub.new
12
12
  adapters[name] = sub
13
+
14
+ sub.prepend(Module.new do
15
+ def call(step, *args, input)
16
+ outcome = super
17
+ ensure
18
+ ::Dry::Mutations::Utils.extend_outcome outcome.value, "#{step.step_name}::#{step.operation_name}"
19
+ end
20
+ end)
13
21
  end
14
22
 
15
23
  def self.adapters
@@ -5,10 +5,6 @@ module Dry
5
5
  # step adapters must provide a single `#call(step, *args, input)` method,
6
6
  # which should return the step’s result wrapped in an `Either` object.
7
7
  class Tranquilo < StepAdapters::Move # :nodoc:
8
- def call(step, *args, input)
9
- # TODO: FIXME: PENDING: when block passing is merged into dry-validation
10
- step.operation.(input, *args)
11
- end
12
8
  end
13
9
  end
14
10
  end
@@ -55,6 +55,17 @@ module Dry
55
55
  end
56
56
 
57
57
  ITSELF = ->(h, k) { h[k] = k }
58
+
59
+ def self.extend_outcome(whatever, host)
60
+ whatever.tap do |outcome|
61
+ outcome.instance_variable_set(:@host, host)
62
+ outcome.extend(Module.new do
63
+ def host
64
+ @host
65
+ end
66
+ end)
67
+ end
68
+ end
58
69
  end
59
70
  end
60
71
  end
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Mutations
3
- VERSION = '1.5.0'.freeze
3
+ VERSION = '1.5.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-mutations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Matiushkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-28 00:00:00.000000000 Z
11
+ date: 2017-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler