vanilla_validator 0.4.8 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a9e98bf5906f1c93ceb3a58c4d9049a39b37ecac9a281c4661e5a1201d4a2b9
4
- data.tar.gz: aeb2828796b9e62ba3b37e038d87619d52aef4dc0183fc973ef2c67575d55f23
3
+ metadata.gz: 1a66408e9f8f86b28d7b3644026c1d0f3d666dc4d00e86b0182b1175c643346a
4
+ data.tar.gz: d640e7f3e16d292bbf7c07bdf80659cff77edee98f72a61db3d1fc514c6883b5
5
5
  SHA512:
6
- metadata.gz: d3201c1726a24cca59b7fa494e63c5c1754f851c9a9ecbdf63dfc62053f32e9f8daa31b94131670b0f84ed8f58063dfc9c46ada459a615eddf82eca4f963a447
7
- data.tar.gz: '0407039760934cb5a51df077c58040648b6d9c2f3ab2a5b5f82b6ca605f03a188705e94a0d13497d041db63362f48aea9000e889b97fda203ddf8fe74841980d'
6
+ metadata.gz: 335aedb210272e9bff3beb84c547bfb200593981b57b072048daa3d402b95fc42b0308db9a724472e4602ffb9249f886d22b29014aa35ca0e6646ee2895180d4
7
+ data.tar.gz: d6d8679249ddeb5a99151c2d1d96fe865ccb3cf3816ca5cbb15671f60d09dcff210db9a3112bc5df7a008b4fa0db89666c9f829e3d2d52307b829d6daf1267f5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vanilla_validator (0.4.7)
4
+ vanilla_validator (0.4.8)
5
5
  activesupport
6
6
  i18n
7
7
  zeitwerk (~> 2.5)
data/README.md CHANGED
@@ -80,9 +80,9 @@ params = {
80
80
  }
81
81
 
82
82
  validation = VanillaValidator.validate(params, {
83
- 'user.addresses.*.state' => 'required|string|in:CA,NY',
83
+ 'user.addresses.*.state' => 'required|alpha|in:CA,NY',
84
84
  'user.orders.*.total' => 'required|numeric|min:0',
85
- 'user.orders.*.status' => 'required|string|in:pending,shipped,delivered'
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
- - [EQ](#eq)
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
- ##### EQ
129
+ ##### Eq
130
130
 
131
131
  ##### Falsy
132
132
 
@@ -0,0 +1,13 @@
1
+ module VanillaValidator
2
+ module Rules
3
+ class Alpha < BaseRule
4
+ def valid?
5
+ value.is_a? String
6
+ end
7
+
8
+ def failure_message
9
+ I18n.t("alpha", attribute: attribute)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,13 +1,13 @@
1
1
  module VanillaValidator
2
- module Rules
3
- class In < BaseRule
4
- def valid?
5
- parameters.include? value.to_s
6
- end
2
+ module Rules
3
+ class In < BaseRule
4
+ def valid?
5
+ parameters.include? value.to_s
6
+ end
7
7
 
8
- def failure_message
9
- I18n.t('in', attribute: attribute)
10
- end
11
- end
12
- end
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
- splited_path = path.split('.')
17
+ def self.get(data, path)
18
+ path_components = path.split('.')
19
19
 
20
- raise "Too many path segments (maximum allowed is 5)" if splited_path.length > 5
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, splited_path)
23
+ self.get_at_wildcard_path(data, path_components)
24
24
  else
25
- self.get_at_explicit_path(data, splited_path)
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.eql?("*")
69
- rpath = path[index.next..-1] || []
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, rpath) }
73
+ result = data.map { |item| get_at_wildcard_path(item, remaining_path) }
76
74
 
77
- return rpath.include?("*") ? result.flatten : result
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 target.is_a?(Array) && ( Integer(segment) rescue false )
83
- target = target[Integer(segment)]
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VanillaValidator
4
- VERSION = "0.4.8"
4
+ VERSION = "0.4.9"
5
5
  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.8
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-15 00:00:00.000000000 Z
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