rails-param-validation 0.7.2 → 0.7.3
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: fac9f3a2c6c7aa70bd5026b8bf82a8e18c245a1a543b6eded39e88ad82ca3a25
|
4
|
+
data.tar.gz: 8c3c4d482872bc47daf52acde3ca18294233b77117479b3890dc01e7d9290b28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17a56f59ef41e16129f1bcc23df6437eb1233799be870787d155652ab76d38c720586a7af7a96a269ee7be449893e0bd82d06b4bae1d755151337dcc2935e487
|
7
|
+
data.tar.gz: d126128c3dcd8feeaa0d381a75a0828564ec986ccf43a9e0a339c310af108504f0712bc1dafa6d41535a6dc2b0872fdf4a3d33d63963922e3ae80704e3222256
|
@@ -1,5 +1,13 @@
|
|
1
1
|
module RailsParamValidation
|
2
2
|
class AlternativesValidator < Validator
|
3
|
+
def self.use_automatic_enums=(enabled)
|
4
|
+
@automatic_enums = enabled
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.automatic_enums?
|
8
|
+
@automatic_enums.nil? ? true : @automatic_enums
|
9
|
+
end
|
10
|
+
|
3
11
|
# @param [Array] schema
|
4
12
|
def initialize(schema, collection)
|
5
13
|
schema = AlternativesValidator.simplify schema
|
@@ -7,32 +15,36 @@ class AlternativesValidator < Validator
|
|
7
15
|
|
8
16
|
@inner_validators = []
|
9
17
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
if
|
15
|
-
previous_enum_values
|
16
|
-
else
|
17
|
-
if validator.constant.class == previous_enum_values.first.class
|
18
|
-
previous_enum_values << value
|
19
|
-
else
|
20
|
-
@inner_validators << ConstantEnumValidator.new(previous_enum_values, collection)
|
18
|
+
if AlternativesValidator.automatic_enums?
|
19
|
+
previous_enum_values = nil
|
20
|
+
schema.each do |value|
|
21
|
+
validator = ValidatorFactory.create(value, collection)
|
22
|
+
if validator.is_a?(ConstantValidator)
|
23
|
+
if previous_enum_values.nil?
|
21
24
|
previous_enum_values = [value]
|
25
|
+
else
|
26
|
+
if validator.constant.class == previous_enum_values.first.class
|
27
|
+
previous_enum_values << value
|
28
|
+
else
|
29
|
+
@inner_validators << ConstantEnumValidator.new(previous_enum_values, collection)
|
30
|
+
previous_enum_values = [value]
|
31
|
+
end
|
22
32
|
end
|
33
|
+
|
34
|
+
next
|
23
35
|
end
|
24
36
|
|
25
|
-
|
37
|
+
if previous_enum_values
|
38
|
+
@inner_validators << ConstantEnumValidator.new(previous_enum_values, collection)
|
39
|
+
previous_enum_values = nil
|
40
|
+
end
|
41
|
+
@inner_validators << validator
|
26
42
|
end
|
27
43
|
|
28
|
-
if previous_enum_values
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
@inner_validators << validator
|
44
|
+
@inner_validators << ConstantEnumValidator.new(previous_enum_values, collection) if previous_enum_values
|
45
|
+
else
|
46
|
+
@inner_validators = schema.map { |value| ValidatorFactory.create(value, collection) }
|
33
47
|
end
|
34
|
-
|
35
|
-
@inner_validators << ConstantEnumValidator.new(previous_enum_values, collection) if previous_enum_values
|
36
48
|
end
|
37
49
|
|
38
50
|
def matches?(path, data)
|