dry-mutations 0.8.10 → 0.8.11
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/lib/dry/mutations/dsl/types.rb +28 -16
- 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: 38e022b61eedee83ed6710525c92bb37aeda3313
|
4
|
+
data.tar.gz: 4fa39a230fc3f8929247c425b2d29aba7e5675d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e15388ad39dbd46471f98658fd44f3e0f7724f5436c3c6abd9bf427c4eeec79e1ba35cb9befaf010e4650660d57fc633f6d223398504950ef22d06a1ee669d04
|
7
|
+
data.tar.gz: 13f8351a663571f345892db471fe73acae4e1a4895a5b5cf3b0408409dc78728754401d5b52a3f82af8b5ab91ff22dfa1d47ea3b4e7f8fbf8e4428a730c390de
|
@@ -48,23 +48,33 @@ module Dry
|
|
48
48
|
########################################################################
|
49
49
|
|
50
50
|
def duck name, **params
|
51
|
-
|
51
|
+
# <<- CLOSURE_SCOPE
|
52
|
+
current = @current
|
53
|
+
params = @environs.merge params if @environs
|
52
54
|
filled_or_maybe = optionality(params)
|
55
|
+
# CLOSURE_SCOPE
|
53
56
|
|
54
57
|
schema do
|
55
58
|
__send__(current, name).__send__(filled_or_maybe, duck?: [*params[:methods]])
|
56
59
|
end
|
60
|
+
|
61
|
+
define_helper_methods name
|
57
62
|
end
|
58
63
|
|
59
64
|
# possible params: `class: nil, builder: nil, new_records: false`
|
60
65
|
def model name, **params
|
66
|
+
# <<- CLOSURE_SCOPE
|
61
67
|
current = @current # closure scope
|
68
|
+
params = @environs.merge params if @environs
|
62
69
|
filled_or_maybe = optionality(params)
|
63
70
|
params[:class] ||= name.to_s.gsub(/(?:\A|_)./) { |m| m[-1].upcase }
|
71
|
+
# CLOSURE_SCOPE
|
64
72
|
|
65
73
|
schema do
|
66
74
|
__send__(current, name).__send__(filled_or_maybe, model?: params[:class])
|
67
75
|
end
|
76
|
+
|
77
|
+
define_helper_methods name
|
68
78
|
end
|
69
79
|
|
70
80
|
########################################################################
|
@@ -74,24 +84,18 @@ module Dry
|
|
74
84
|
def generic_type name = nil, **params
|
75
85
|
fail Errors::AnonymousTypeDetected.new(__callee__) if name.nil?
|
76
86
|
|
77
|
-
|
78
|
-
|
79
|
-
# FIXME: :strip => true and siblings should be handled with procs?
|
87
|
+
# <<- CLOSURE_SCOPE
|
80
88
|
current = @current # closure scope
|
81
|
-
|
82
|
-
opts = Utils.Guards(params)
|
83
|
-
|
89
|
+
params = @environs.merge params if @environs
|
84
90
|
type = [optionality(params), Utils.Type(__callee__)]
|
91
|
+
opts = Utils.Guards(params)
|
92
|
+
# CLOSURE_SCOPE
|
85
93
|
|
86
94
|
schema do
|
87
95
|
Utils.smart_send(__send__(current, name), *type, **opts)
|
88
96
|
end
|
89
97
|
|
90
|
-
|
91
|
-
define_method(name) { @inputs[name] }
|
92
|
-
define_method(:"#{name}_present?") { @inputs.key?(name) }
|
93
|
-
define_method(:"#{name}=") { |value| @inputs[name] = value }
|
94
|
-
end
|
98
|
+
define_helper_methods name
|
95
99
|
end
|
96
100
|
|
97
101
|
%i(string integer float date time boolean).each do |m|
|
@@ -102,10 +106,18 @@ module Dry
|
|
102
106
|
|
103
107
|
private
|
104
108
|
|
105
|
-
def optionality
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
+
def optionality params
|
110
|
+
nils, empty = params.delete(:nils), params.delete(:empty)
|
111
|
+
# FIXME: Should we treat `empty?` in some specific way?
|
112
|
+
nils || empty ? :maybe : :filled
|
113
|
+
end
|
114
|
+
|
115
|
+
def define_helper_methods name
|
116
|
+
unless Nested === self
|
117
|
+
define_method(name) { @inputs[name] }
|
118
|
+
define_method(:"#{name}_present?") { @inputs.key?(name) }
|
119
|
+
define_method(:"#{name}=") { |value| @inputs[name] = value }
|
120
|
+
end
|
109
121
|
end
|
110
122
|
end
|
111
123
|
end
|