dry_validation_parser 0.1.3 → 0.1.5
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccb12036211270788b640b218b3f50906ad6f8daf79c683e82b2ba4f4e9730b0
|
4
|
+
data.tar.gz: 9cf5b8d262ce584279af7b43566d148fa2ee224cc74630689ac5c824aca7b0f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8be3fe48b53e530f316af84f4910d6a5d225b78b76de0fed4dbca1bff7435e69cf5d94ad24bd46bd98b924eff745c79aa2bb413e45c3d917b52cc3615e5d8c72
|
7
|
+
data.tar.gz: 4c118798fc0736758d95587a63098917dea8bcb5f02a8dccf799bf69619409295ed03ab120f367b6906d5b663da2877480a10f035217b3072546cc26811314ac
|
@@ -16,6 +16,16 @@ module DryValidationParser
|
|
16
16
|
time?: "time"
|
17
17
|
}.freeze
|
18
18
|
|
19
|
+
DESCRIPTION_MAPPING = {
|
20
|
+
eql?: "Must be equal to %{value}",
|
21
|
+
max_size?: "Maximum size: %{value}",
|
22
|
+
min_size?: "Minimum size: %{value}",
|
23
|
+
gteq?: "Greater than or equal to %{value}",
|
24
|
+
gt?: "Greater than %{value}",
|
25
|
+
lt?: "Lower than %{value}",
|
26
|
+
lteq?: "Lower than or equal to %{value}",
|
27
|
+
}.freeze
|
28
|
+
|
19
29
|
# @api private
|
20
30
|
attr_reader :keys
|
21
31
|
|
@@ -106,6 +116,22 @@ module DryValidationParser
|
|
106
116
|
keys[key][:enum] += [nil] if opts.fetch(:nullable, false)
|
107
117
|
elsif PREDICATE_TO_TYPE[name]
|
108
118
|
keys[key][:type] = PREDICATE_TO_TYPE[name]
|
119
|
+
else
|
120
|
+
description = predicate_description(name.to_s, rest[0][1].to_s)
|
121
|
+
if keys[key][:description].to_s.empty?
|
122
|
+
keys[key][:description] = description unless description.to_s.empty?
|
123
|
+
else
|
124
|
+
keys[key][:description] += ", #{description}" unless description.to_s.empty?
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def predicate_description(name, value)
|
130
|
+
if ::I18n.locale_available?(::I18n.locale)
|
131
|
+
::I18n.t("contract.descriptions.#{name}", value: value, default: '')
|
132
|
+
else
|
133
|
+
description = DESCRIPTION_MAPPING[name]
|
134
|
+
description ? description % { value: 5 } : ""
|
109
135
|
end
|
110
136
|
end
|
111
137
|
end
|