dry-mutations 0.99.1 → 0.99.2

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: b84498f83aab334053ceadcf35a12ab919af5fdb
4
- data.tar.gz: 508f7a5805a93949d189a6dfe06148f456a25562
3
+ metadata.gz: 2737879381ea7e6b16728251b38259eb487a6ec3
4
+ data.tar.gz: 678d954f5325839ee83665614039fa848ace4573
5
5
  SHA512:
6
- metadata.gz: 711ab39269cf47bfaee78acc30daff353dc274f1450b2746fac79fd4b3d7a186d7b0d1ae97c060f075231bfbcf8075ce5fab7b34070ed70b50d4fcb22537708b
7
- data.tar.gz: 777c72b07f23f37659ec2aa788220122e940bb2bf5cad9fa81b82854312b8b56839ef4b3785ddc66d896a0095edd7f02b411befdfa84864e406ffc44cc5cea12
6
+ metadata.gz: f1c48b5bc25691331145a708e87e1745c091f17f5f6291a308eb491863433e7c5e410e55cf8d6dc19dedda46d8395f20a0e6497d9b5db720cf05b7422629ac7c
7
+ data.tar.gz: 00c2063c2b10bcf5a29323aaa4b53e8d580920100ccdfd83ab65d8a3cc266ca4222abc894f56194c2ba5bdaf311da051230ca6a4ea2299a3bca9ee0ad8809502
data/config/messages.yml CHANGED
@@ -4,3 +4,4 @@ en:
4
4
  model?: 'must be a model (instance of %{expected})'
5
5
  discard_empty: 'aleksei’s too dumb error (%{expected},) you won :-P'
6
6
  default?: 'default value implementation sucks'
7
+ class: 'class guard for arrays implementation sucks'
@@ -42,7 +42,13 @@ module Dry
42
42
  Utils.Type err.type
43
43
  end
44
44
 
45
- name.nil? ? schema { each(nested) } : schema { __send__(current, name).each(nested) }
45
+ case
46
+ when !params[:class].nil? # cb.nil?
47
+ type = Utils.Type(params.delete(:class))
48
+ schema { Utils.smart_send(__send__(current, name), *(type ? [:each, type] : [:maybe])) }
49
+ when name.nil? then schema { each(nested) } # FIXME: CAN IT BE NIL?!
50
+ else schema { __send__(current, name).each(nested) }
51
+ end
46
52
 
47
53
  case
48
54
  when params[:discard_empty] then schema.discarded!(name)
@@ -28,6 +28,10 @@ module Dry
28
28
  predicate(:discard_empty) do |_expected, _current|
29
29
  true
30
30
  end
31
+
32
+ predicate(:class) do |_expected, _current|
33
+ true
34
+ end
31
35
  end
32
36
  end
33
37
  end
@@ -1,6 +1,8 @@
1
+ require 'dry-types'
1
2
  module Dry
2
3
  module Mutations
3
4
  module Utils # :nodoc:
5
+ DRY_TYPES = ::Dry::Types.type_keys.grep(/\A[^.]+\z/)
4
6
  DRY_TO_MUTATIONS = {
5
7
  min_size?: :min_length,
6
8
  max_size?: :max_length,
@@ -12,6 +14,11 @@ module Dry
12
14
  }.freeze
13
15
  MUTATIONS_TO_DRY = DRY_TO_MUTATIONS.invert.merge(default: :default?).freeze
14
16
 
17
+ ##########################################################################
18
+ COERCIBLE_STRING = ::Dry::Types::Constructor.new(
19
+ ::Dry::Types['strict.string'], fn: ->(v) { v.to_s.strip }
20
+ )
21
+
15
22
  def self.RawInputs *args
16
23
  args.inject(Utils.Hash({})) do |h, arg|
17
24
  h.merge! case arg
@@ -40,16 +47,14 @@ module Dry
40
47
  end
41
48
 
42
49
  def self.Type type, **params
43
- case type.to_s
50
+ case Snake(type)
44
51
  when 'string'
45
52
  if Falsey?(params[:strip])
46
53
  :str?
47
54
  else
48
55
  # TODO: this silently coerces everything to be a string
49
56
  # when `param[:strip]` is specified. This is likely OK, though.
50
- ::Dry::Types::Constructor.new(
51
- ::Dry::Types['strict.string'], fn: ->(v) { v.to_s.strip }
52
- )
57
+ COERCIBLE_STRING
53
58
  end
54
59
  when 'date'
55
60
  ::Dry::Types::Constructor.new(
@@ -73,7 +78,8 @@ module Dry
73
78
  end
74
79
  end
75
80
  )
76
- else :"#{type}?"
81
+ when -> (t) { DRY_TYPES.include?(t) } then :"#{type}?"
82
+ # else nil # implicit # FIXME: IS IT OK?
77
83
  end
78
84
  end
79
85
 
@@ -1,5 +1,5 @@
1
1
  module Dry
2
2
  module Mutations
3
- VERSION = '0.99.1'.freeze
3
+ VERSION = '0.99.2'.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: 0.99.1
4
+ version: 0.99.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksei Matiushkin