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: 7efa327265bfc8ad86d510b2b014660923870715ba895a9a470d6792bccb13ed
4
- data.tar.gz: a641151602952abad4053e6341ebb6ba1f46900ef022fe69c97ec9271920685c
3
+ metadata.gz: fac9f3a2c6c7aa70bd5026b8bf82a8e18c245a1a543b6eded39e88ad82ca3a25
4
+ data.tar.gz: 8c3c4d482872bc47daf52acde3ca18294233b77117479b3890dc01e7d9290b28
5
5
  SHA512:
6
- metadata.gz: 2a2d85cde19d9230454e0dee45a72fddf7dc4a336d80fb812596ab04099f01110cb107bb67329b2c9a87ef490434c899065ef16c6a4a8b25b98b334882b4873f
7
- data.tar.gz: 0d9be5ee82de94347d95d0cfa28947f83c769089ddaf41708b3a527db274b8033190bdf7bff19f0ff8db84781fde947e24e49d4d819a028fd65d462d2f94ffde
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
- previous_enum_values = nil
11
- schema.each do |value|
12
- validator = ValidatorFactory.create(value, collection)
13
- if validator.is_a?(ConstantValidator)
14
- if previous_enum_values.nil?
15
- previous_enum_values = [value]
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
- next
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
- @inner_validators << ConstantEnumValidator.new(previous_enum_values, collection)
30
- previous_enum_values = nil
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)
@@ -1,3 +1,3 @@
1
1
  module RailsParamValidation
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-param-validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oskar Kirmis