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 +4 -4
- data/config/messages.yml +1 -0
- data/lib/dry/mutations/dsl/types.rb +7 -1
- data/lib/dry/mutations/predicates.rb +4 -0
- data/lib/dry/mutations/utils/dry-mutations.rb +11 -5
- data/lib/dry/mutations/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2737879381ea7e6b16728251b38259eb487a6ec3
|
4
|
+
data.tar.gz: 678d954f5325839ee83665614039fa848ace4573
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1c48b5bc25691331145a708e87e1745c091f17f5f6291a308eb491863433e7c5e410e55cf8d6dc19dedda46d8395f20a0e6497d9b5db720cf05b7422629ac7c
|
7
|
+
data.tar.gz: 00c2063c2b10bcf5a29323aaa4b53e8d580920100ccdfd83ab65d8a3cc266ca4222abc894f56194c2ba5bdaf311da051230ca6a4ea2299a3bca9ee0ad8809502
|
data/config/messages.yml
CHANGED
@@ -42,7 +42,13 @@ module Dry
|
|
42
42
|
Utils.Type err.type
|
43
43
|
end
|
44
44
|
|
45
|
-
|
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)
|
@@ -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
|
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
|
-
|
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
|
-
|
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
|
|