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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b9a36a11f7ac423bc0a287e56f7955f8e55bfd3
4
- data.tar.gz: c3e7009846e8dcbfe5c898f8332540fad3d48e93
3
+ metadata.gz: 6db4f0000ca0dc902cb4182e5079d0b5685473ab
4
+ data.tar.gz: f78b3976ccd11487bfd6da545f90d36e294300fd
5
5
  SHA512:
6
- metadata.gz: 72eff94bdc14331b0fa44fabc3ee0db5bd04ba2bceca112cedb452a35f04a2a587b39988988f3e3faf38677ffada2d445a1cf719b203d20100747adb3be21b72
7
- data.tar.gz: 2ec5d6cfa1e2d7668faf340b5c32aa69706d175caa1f1c40d19b5b88daede7f54e25cad3a741b58f9d06b6f3ddd9104109746975d2f1727a1f3c0df95aa10442
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: 'dry-rb/dry-transaction'
9
+ gem 'dry-transaction', github: 'am-kantox/dry-transaction'
10
10
 
11
11
  gem 'codeclimate-test-reporter', group: :test, require: nil
@@ -11,6 +11,12 @@ module Dry
11
11
 
12
12
  class TypeError < StandardError # :nodoc:
13
13
  end
14
+
15
+ class ChainExecutionError < StandardError # :nodoc:
16
+ def initialize left
17
+ super left.inspect # FIXME
18
+ end
19
+ end
14
20
  end
15
21
  end
16
22
  end
@@ -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?(&current.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
@@ -8,6 +8,8 @@ module Dry
8
8
  # step :persist
9
9
  # end
10
10
  module DSL # :nodoc:
11
+ include Dry::Monads::Either::Mixin
12
+
11
13
  def chain **params
12
14
  return enum_for(:chain) unless block_given? # FIXME: Needed? Works? Remove?
13
15
 
@@ -17,8 +17,7 @@ module Dry
17
17
  end
18
18
 
19
19
  def call(step, *args, input)
20
- binding.pry unless args.empty? # FIXME
21
- step.operation.(input)
20
+ step.operation.(input, *args)
22
21
  end
23
22
  end
24
23
 
@@ -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
@@ -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(&params.method(:[])))
102
103
  .to_h
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Mutations
3
- VERSION = '0.8.8'.freeze
3
+ VERSION = '0.8.9'.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: 0.8.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-14 00:00:00.000000000 Z
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