vanilla_validator 0.4.7 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4af0d919b137fc2f9f0da89804d628b4c617349ad04d6a149ddbaadd413466a
4
- data.tar.gz: 376f312e9dcac54a409ccf9b54ddec406f34ec535abd6d23a5aff19b6e9c6b86
3
+ metadata.gz: 1a66408e9f8f86b28d7b3644026c1d0f3d666dc4d00e86b0182b1175c643346a
4
+ data.tar.gz: d640e7f3e16d292bbf7c07bdf80659cff77edee98f72a61db3d1fc514c6883b5
5
5
  SHA512:
6
- metadata.gz: 9eac34e3c471596e8f02dad646053fe46a387971efac7fbd57d1997b2db78dd0e8368143d827a085dd39d9ff47e1bcd46bc2a6ba8b042bfbcaa123e9c8f731f7
7
- data.tar.gz: 836fb3f32057e0815586bd0099904bfe4c3749e404d60f03c38ab88b33a3b5ce2466fa1bd57d5b8e8270de86a0d04f158d3bc82fe58f439cc640bc6eb86be761
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.2)
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
 
@@ -8,8 +8,6 @@ module VanillaValidator
8
8
  @errors = errors.with_indifferent_access
9
9
  end
10
10
 
11
- alias :valid? :success?
12
-
13
11
  def success?
14
12
  errors.empty?
15
13
  end
@@ -17,5 +15,7 @@ module VanillaValidator
17
15
  def failed?
18
16
  errors.any?
19
17
  end
18
+
19
+ alias :valid? :success?
20
20
  end
21
21
  end
@@ -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.7"
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.7
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