dry-mutations 0.8.8 → 0.8.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/dry/mutations/errors.rb +6 -0
- data/lib/dry/mutations/extensions/command.rb +3 -1
- data/lib/dry/mutations/predicates.rb +4 -0
- data/lib/dry/mutations/transactions/container.rb +1 -0
- data/lib/dry/mutations/transactions/dsl.rb +2 -0
- data/lib/dry/mutations/transactions/step_adapters.rb +1 -2
- data/lib/dry/mutations/transactions/step_adapters/tranquilo.rb +14 -0
- data/lib/dry/mutations/utils.rb +3 -2
- data/lib/dry/mutations/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6db4f0000ca0dc902cb4182e5079d0b5685473ab
|
4
|
+
data.tar.gz: f78b3976ccd11487bfd6da545f90d36e294300fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f690db87ad1b42c90562306ede3f3436350b1800233b8c266f4af58eab9d94b68824349a2e273181ae21e21c4b268871b23f93783caaaccbe3d7a888b7d55440
|
7
|
+
data.tar.gz: 35e1ce292e6061a21c27c53d28a5092cc281a1f7f4bdf031b19c1190e1a1637477315b8d6f386628efb161df1ff88ae6643def51ef6d0d775f00544a980a821f
|
data/Gemfile
CHANGED
@@ -6,6 +6,6 @@ gemspec
|
|
6
6
|
gem 'dry-validation', github: 'dry-rb/dry-validation'
|
7
7
|
gem 'dry-monads', github: 'dry-rb/dry-monads'
|
8
8
|
gem 'dry-matcher', github: 'dry-rb/dry-matcher'
|
9
|
-
gem 'dry-transaction', github: '
|
9
|
+
gem 'dry-transaction', github: 'am-kantox/dry-transaction'
|
10
10
|
|
11
11
|
gem 'codeclimate-test-reporter', group: :test, require: nil
|
data/lib/dry/mutations/errors.rb
CHANGED
@@ -2,6 +2,8 @@ module Dry
|
|
2
2
|
module Mutations
|
3
3
|
module Extensions
|
4
4
|
module Command # :nodoc:
|
5
|
+
include Dry::Monads::Either::Mixin
|
6
|
+
|
5
7
|
def self.prepended base
|
6
8
|
fail ArgumentError, "Can not prepend #{self.class} to #{base.class}: base class must be a ::Mutations::Command descendant." unless base < ::Mutations::Command
|
7
9
|
base.extend(DSL::Module) unless base.ancestors.include?(DSL::Module)
|
@@ -17,7 +19,6 @@ module Dry
|
|
17
19
|
if base.name && !::Kernel.methods.include?(base_name = base.name.split('::').last.to_sym)
|
18
20
|
::Kernel.class_eval <<-FACTORY, __FILE__, __LINE__ + 1
|
19
21
|
def #{base_name}(*args)
|
20
|
-
puts "Gonna call [#{base}.call(*args)] with \#{args.inspect}"
|
21
22
|
#{base}.call(*args)
|
22
23
|
end
|
23
24
|
FACTORY
|
@@ -35,6 +36,7 @@ module Dry
|
|
35
36
|
|
36
37
|
def initialize(*args)
|
37
38
|
@raw_inputs = args.inject(Utils.Hash({})) do |h, arg|
|
39
|
+
arg = arg.value if arg.is_a?(Right)
|
38
40
|
fail ArgumentError.new("All arguments must be hashes. Given: #{args.inspect}.") unless arg.is_a?(Hash)
|
39
41
|
h.merge!(arg)
|
40
42
|
end
|
@@ -7,6 +7,10 @@ module Dry
|
|
7
7
|
expected.empty? || expected.all?(¤t.method(:respond_to?))
|
8
8
|
end
|
9
9
|
|
10
|
+
predicate(:default?) do |_expected, _current|
|
11
|
+
fail Errors::TypeError, "“default” guard is not implemented yet in dry-mutations, sorry for that."
|
12
|
+
end
|
13
|
+
|
10
14
|
# FIXME: at the moment this is an exact equivalent of :type? => User
|
11
15
|
predicate(:model?) do |expected, current|
|
12
16
|
return true if expected.nil?
|
@@ -2,6 +2,7 @@ module Dry
|
|
2
2
|
module Mutations
|
3
3
|
module Transactions # :nodoc:
|
4
4
|
Container = lambda do |whatever|
|
5
|
+
return ->(*input) { input } unless whatever
|
5
6
|
whatever.respond_to?(:call) ? whatever : Utils.Constant(whatever).tap do |p|
|
6
7
|
fail ArgumentError, "The argument must respond to :call, though #{k.inspect} passed." unless p.respond_to? :call
|
7
8
|
end
|
@@ -0,0 +1,14 @@
|
|
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
|
+
class Tranquilo < StepAdapters::Move # :nodoc:
|
8
|
+
def call(step, *args, input)
|
9
|
+
step.operation.(input, *args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/dry/mutations/utils.rb
CHANGED
@@ -76,6 +76,7 @@ module Dry
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
+
ITSELF = ->(h, k) { h[k] = k }
|
79
80
|
DRY_TO_MUTATIONS = {
|
80
81
|
min_size?: :min_length,
|
81
82
|
max_size?: :max_length,
|
@@ -85,7 +86,7 @@ module Dry
|
|
85
86
|
gteq?: :min,
|
86
87
|
lteq?: :max
|
87
88
|
}.freeze
|
88
|
-
MUTATIONS_TO_DRY = DRY_TO_MUTATIONS.invert.freeze
|
89
|
+
MUTATIONS_TO_DRY = DRY_TO_MUTATIONS.invert.merge(default: :default?).freeze
|
89
90
|
|
90
91
|
# Fuzzy converts params between different implementaions
|
91
92
|
def self.Guards *keys, **params
|
@@ -96,7 +97,7 @@ module Dry
|
|
96
97
|
|
97
98
|
map = [DRY_TO_MUTATIONS, MUTATIONS_TO_DRY].detect do |h|
|
98
99
|
(h.keys & keys).any?
|
99
|
-
end
|
100
|
+
end || Hash.new(&ITSELF)
|
100
101
|
|
101
102
|
map.values_at(*keys).zip(keys.map(¶ms.method(:[])))
|
102
103
|
.to_h
|
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: 0.8.
|
4
|
+
version: 0.8.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Matiushkin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -223,6 +223,7 @@ files:
|
|
223
223
|
- lib/dry/mutations/transactions/dsl.rb
|
224
224
|
- lib/dry/mutations/transactions/step_adapters.rb
|
225
225
|
- lib/dry/mutations/transactions/step_adapters/mutate.rb
|
226
|
+
- lib/dry/mutations/transactions/step_adapters/tranquilo.rb
|
226
227
|
- lib/dry/mutations/transactions/step_adapters/transform.rb
|
227
228
|
- lib/dry/mutations/transactions/step_adapters/validate.rb
|
228
229
|
- lib/dry/mutations/transactions/wrapper.rb
|