vanilla_validator 0.4.8 → 0.4.9
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/Gemfile.lock +1 -1
- data/README.md +4 -4
- data/lib/vanilla_validator/rules/alpha.rb +13 -0
- data/lib/vanilla_validator/rules/in.rb +10 -10
- data/lib/vanilla_validator/value_extractor.rb +12 -14
- data/lib/vanilla_validator/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a66408e9f8f86b28d7b3644026c1d0f3d666dc4d00e86b0182b1175c643346a
|
4
|
+
data.tar.gz: d640e7f3e16d292bbf7c07bdf80659cff77edee98f72a61db3d1fc514c6883b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 335aedb210272e9bff3beb84c547bfb200593981b57b072048daa3d402b95fc42b0308db9a724472e4602ffb9249f886d22b29014aa35ca0e6646ee2895180d4
|
7
|
+
data.tar.gz: d6d8679249ddeb5a99151c2d1d96fe865ccb3cf3816ca5cbb15671f60d09dcff210db9a3112bc5df7a008b4fa0db89666c9f829e3d2d52307b829d6daf1267f5
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -80,9 +80,9 @@ params = {
|
|
80
80
|
}
|
81
81
|
|
82
82
|
validation = VanillaValidator.validate(params, {
|
83
|
-
'user.addresses.*.state' => 'required|
|
83
|
+
'user.addresses.*.state' => 'required|alpha|in:CA,NY',
|
84
84
|
'user.orders.*.total' => 'required|numeric|min:0',
|
85
|
-
'user.orders.*.status' => 'required|
|
85
|
+
'user.orders.*.status' => 'required|alpha|in:pending,shipped,delivered'
|
86
86
|
})
|
87
87
|
```
|
88
88
|
|
@@ -94,7 +94,7 @@ validation = VanillaValidator.validate(params, {
|
|
94
94
|
- [Boolean](#boolean)
|
95
95
|
- [Date](#date)
|
96
96
|
- [Email](#email)
|
97
|
-
- [
|
97
|
+
- [Equal](#eq)
|
98
98
|
- [Falsy](#falsy)
|
99
99
|
- [Gte](#gte)
|
100
100
|
- [In](#in)
|
@@ -126,7 +126,7 @@ The validated field must have a value that is after a specified date.
|
|
126
126
|
|
127
127
|
##### Email
|
128
128
|
|
129
|
-
#####
|
129
|
+
##### Eq
|
130
130
|
|
131
131
|
##### Falsy
|
132
132
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module VanillaValidator
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
module Rules
|
3
|
+
class In < BaseRule
|
4
|
+
def valid?
|
5
|
+
parameters.include? value.to_s
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def failure_message
|
9
|
+
I18n.t('in', attribute: attribute)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
13
|
end
|
@@ -14,15 +14,15 @@ module VanillaValidator
|
|
14
14
|
#
|
15
15
|
# Returns: The extracted data, or nil if the path does not lead to a valid value.
|
16
16
|
#
|
17
|
-
def self.get(data, path)
|
18
|
-
|
17
|
+
def self.get(data, path)
|
18
|
+
path_components = path.split('.')
|
19
19
|
|
20
|
-
raise "Too many path segments (maximum allowed is 5)" if
|
20
|
+
raise "Too many path segments (maximum allowed is 5)" if path_components.length > 5
|
21
21
|
|
22
22
|
if path.include?("*")
|
23
|
-
self.get_at_wildcard_path(data,
|
23
|
+
self.get_at_wildcard_path(data, path_components)
|
24
24
|
else
|
25
|
-
self.get_at_explicit_path(data,
|
25
|
+
self.get_at_explicit_path(data, path_components)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -65,22 +65,20 @@ module VanillaValidator
|
|
65
65
|
path.each_with_index do |segment, index|
|
66
66
|
return data if segment.nil?
|
67
67
|
|
68
|
-
if segment
|
69
|
-
|
68
|
+
if segment == "*"
|
69
|
+
remaining_path = path[index.next..-1] || []
|
70
70
|
|
71
|
-
unless data.is_a?(Array)
|
72
|
-
return default
|
73
|
-
end
|
71
|
+
return default unless data.is_a?(Array)
|
74
72
|
|
75
|
-
result = data.map { |item| get_at_wildcard_path(item,
|
73
|
+
result = data.map { |item| get_at_wildcard_path(item, remaining_path) }
|
76
74
|
|
77
|
-
return
|
75
|
+
return remaining_path.include?("*") ? result.flatten : result
|
78
76
|
end
|
79
77
|
|
80
78
|
if data.is_a?(Hash) && data.key?(segment)
|
81
79
|
data = data[segment]
|
82
|
-
elsif
|
83
|
-
|
80
|
+
elsif data.is_a?(Array) && ( Integer(segment) rescue false )
|
81
|
+
data = data[Integer(segment)]
|
84
82
|
else
|
85
83
|
return default
|
86
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vanilla_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Farid Mohammadi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/vanilla_validator/rule_parser.rb
|
88
88
|
- lib/vanilla_validator/rules/after.rb
|
89
89
|
- lib/vanilla_validator/rules/after_or_equal.rb
|
90
|
+
- lib/vanilla_validator/rules/alpha.rb
|
90
91
|
- lib/vanilla_validator/rules/base_rule.rb
|
91
92
|
- lib/vanilla_validator/rules/before.rb
|
92
93
|
- lib/vanilla_validator/rules/before_or_equal.rb
|