validate-params 0.14.1 → 0.16.0
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/CHANGELOG.md +12 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +26 -24
- data/README.md +2 -0
- data/config/locales/en.yml +1 -0
- data/lib/validate_params/param_validator.rb +21 -2
- data/lib/validate_params/types/boolean.rb +21 -0
- data/lib/validate_params/types/date_time.rb +3 -1
- data/lib/validate_params/validatable.rb +3 -1
- data/lib/validate_params/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: 77ad49f477340257039775213f6c8ebd6bbaf6eb79ab49b298bd50d6fab88291
|
|
4
|
+
data.tar.gz: 522314281864e41faeea4a67857bd856fe0f02211d0f7ff5c2b84c761b1395da
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dec501d625c7a0ff55f23ce26cfec0b504808a6d4ac5b33e584152fb996905873cce9b443701aa6ef3990de2356d4fe16a2384ef7edeb4a24dd6da5f53168d3e
|
|
7
|
+
data.tar.gz: edd03c3b475a23a5f022aba35edf995df6b332aa7e29fb43bac62e62f25393d238b37e0c7dac24075227cfb84e9e1f2d6aa3844fcb312b4f4153dbeb74fcba61
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [0.16.0] - 2025-11-25
|
|
2
|
+
|
|
3
|
+
- Support `:in` options to Array, of: String
|
|
4
|
+
|
|
5
|
+
## [0.15.1] - 2025-10-14
|
|
6
|
+
|
|
7
|
+
- Fixed issue with DateTime type validation to reject timestamps that result in years greater than 9999
|
|
8
|
+
|
|
9
|
+
## [0.15.0] - 2025-09-26
|
|
10
|
+
|
|
11
|
+
- Support for boolean type has been added
|
|
12
|
+
|
|
1
13
|
## [0.14.1] - 2025-07-15
|
|
2
14
|
|
|
3
15
|
- Fixed issue with `scrub_invalid_utf8` option in String type to ensure it works correctly with non-string inputs
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
validate-params (0.
|
|
4
|
+
validate-params (0.16.0)
|
|
5
5
|
activesupport (>= 6.1.0)
|
|
6
6
|
i18n (>= 1.6)
|
|
7
7
|
|
|
@@ -27,7 +27,7 @@ GEM
|
|
|
27
27
|
minitest (>= 5.1)
|
|
28
28
|
tzinfo (~> 2.0)
|
|
29
29
|
zeitwerk (~> 2.3)
|
|
30
|
-
ast (2.4.
|
|
30
|
+
ast (2.4.3)
|
|
31
31
|
builder (3.2.4)
|
|
32
32
|
concurrent-ruby (1.2.3)
|
|
33
33
|
crass (1.0.6)
|
|
@@ -35,8 +35,9 @@ GEM
|
|
|
35
35
|
erubi (1.12.0)
|
|
36
36
|
i18n (1.14.5)
|
|
37
37
|
concurrent-ruby (~> 1.0)
|
|
38
|
-
json (2.
|
|
39
|
-
language_server-protocol (3.17.0.
|
|
38
|
+
json (2.16.0)
|
|
39
|
+
language_server-protocol (3.17.0.5)
|
|
40
|
+
lint_roller (1.1.0)
|
|
40
41
|
loofah (2.21.1)
|
|
41
42
|
crass (~> 1.0.2)
|
|
42
43
|
nokogiri (>= 1.5.9)
|
|
@@ -45,12 +46,13 @@ GEM
|
|
|
45
46
|
nokogiri (1.15.6)
|
|
46
47
|
mini_portile2 (~> 2.8.2)
|
|
47
48
|
racc (~> 1.4)
|
|
48
|
-
parallel (1.
|
|
49
|
-
parser (3.3.0
|
|
49
|
+
parallel (1.27.0)
|
|
50
|
+
parser (3.3.10.0)
|
|
50
51
|
ast (~> 2.4.1)
|
|
51
52
|
racc
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
prism (1.6.0)
|
|
54
|
+
racc (1.8.1)
|
|
55
|
+
rack (2.2.20)
|
|
54
56
|
rack-test (2.1.0)
|
|
55
57
|
rack (>= 1.3)
|
|
56
58
|
rails-dom-testing (2.0.3)
|
|
@@ -59,10 +61,8 @@ GEM
|
|
|
59
61
|
rails-html-sanitizer (1.5.0)
|
|
60
62
|
loofah (~> 2.19, >= 2.19.1)
|
|
61
63
|
rainbow (3.1.1)
|
|
62
|
-
rake (13.
|
|
63
|
-
regexp_parser (2.
|
|
64
|
-
rexml (3.2.8)
|
|
65
|
-
strscan (>= 3.0.9)
|
|
64
|
+
rake (13.3.1)
|
|
65
|
+
regexp_parser (2.11.3)
|
|
66
66
|
rspec (3.13.0)
|
|
67
67
|
rspec-core (~> 3.13.0)
|
|
68
68
|
rspec-expectations (~> 3.13.0)
|
|
@@ -76,24 +76,26 @@ GEM
|
|
|
76
76
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
77
77
|
rspec-support (~> 3.13.0)
|
|
78
78
|
rspec-support (3.13.0)
|
|
79
|
-
rubocop (1.
|
|
79
|
+
rubocop (1.81.7)
|
|
80
80
|
json (~> 2.3)
|
|
81
|
-
language_server-protocol (
|
|
81
|
+
language_server-protocol (~> 3.17.0.2)
|
|
82
|
+
lint_roller (~> 1.1.0)
|
|
82
83
|
parallel (~> 1.10)
|
|
83
84
|
parser (>= 3.3.0.2)
|
|
84
85
|
rainbow (>= 2.2.2, < 4.0)
|
|
85
|
-
regexp_parser (>=
|
|
86
|
-
|
|
87
|
-
rubocop-ast (>= 1.31.1, < 2.0)
|
|
86
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
87
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
88
88
|
ruby-progressbar (~> 1.7)
|
|
89
|
-
unicode-display_width (>= 2.4.0, <
|
|
90
|
-
rubocop-ast (1.
|
|
91
|
-
parser (>= 3.3.
|
|
89
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
90
|
+
rubocop-ast (1.48.0)
|
|
91
|
+
parser (>= 3.3.7.2)
|
|
92
|
+
prism (~> 1.4)
|
|
92
93
|
ruby-progressbar (1.13.0)
|
|
93
|
-
strscan (3.1.0)
|
|
94
94
|
tzinfo (2.0.6)
|
|
95
95
|
concurrent-ruby (~> 1.0)
|
|
96
|
-
unicode-display_width (2.
|
|
96
|
+
unicode-display_width (3.2.0)
|
|
97
|
+
unicode-emoji (~> 4.1)
|
|
98
|
+
unicode-emoji (4.1.0)
|
|
97
99
|
zeitwerk (2.6.8)
|
|
98
100
|
|
|
99
101
|
PLATFORMS
|
|
@@ -102,9 +104,9 @@ PLATFORMS
|
|
|
102
104
|
DEPENDENCIES
|
|
103
105
|
actionpack (>= 6.1.0)
|
|
104
106
|
bundler (~> 2.0)
|
|
105
|
-
rake (~> 13.
|
|
107
|
+
rake (~> 13.3)
|
|
106
108
|
rspec (~> 3.0)
|
|
107
|
-
rubocop (~> 1.
|
|
109
|
+
rubocop (~> 1.81)
|
|
108
110
|
validate-params!
|
|
109
111
|
|
|
110
112
|
BUNDLED WITH
|
data/README.md
CHANGED
|
@@ -50,6 +50,7 @@ class TestController < ActionController::Base
|
|
|
50
50
|
p.param :user_ids, Array, of: Integer, default: [1, 2, 3]
|
|
51
51
|
p.param :states, Array, of: String, default: ["active", "inactive"], reject_blank: true
|
|
52
52
|
p.param :file, IO, min: 1.byte, max: 1.megabyte
|
|
53
|
+
p.param :active, :boolean, default: true
|
|
53
54
|
p.param :date_of_birth, Hash do |pp|
|
|
54
55
|
pp.param :gt, Date, min: Date.new(2020, 1, 1), max: Date.new(2021, 1, 1)
|
|
55
56
|
pp.param :lt, Date
|
|
@@ -78,6 +79,7 @@ Here are the following supported types along with operations supported.
|
|
|
78
79
|
- IO (required, min, max)
|
|
79
80
|
- Array of: (String|Integer|Float) (default, reject_blank)
|
|
80
81
|
- Hash - Nested block of types
|
|
82
|
+
- Boolean (required, default)
|
|
81
83
|
|
|
82
84
|
|
|
83
85
|
### Params mutation
|
data/config/locales/en.yml
CHANGED
|
@@ -3,5 +3,6 @@ en:
|
|
|
3
3
|
required: "%{param} is required"
|
|
4
4
|
invalid_type: "%{param} must be a valid %{type}"
|
|
5
5
|
invalid_in: "%{param} is an invalid value"
|
|
6
|
+
array_invalid_in: "%{param} has an invalid values: %{values}"
|
|
6
7
|
more_than_max: "%{param} cannot be more than maximum"
|
|
7
8
|
less_than_min: "%{param} cannot be less than minimum"
|
|
@@ -38,9 +38,12 @@ module ValidateParams
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def array
|
|
41
|
-
|
|
41
|
+
unless Types::Array.valid?(@value, **@options)
|
|
42
|
+
@errors << { message: error_message }
|
|
43
|
+
return
|
|
44
|
+
end
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
array_validate_inclusion if @options[:in].present?
|
|
44
47
|
end
|
|
45
48
|
|
|
46
49
|
def date
|
|
@@ -109,6 +112,12 @@ module ValidateParams
|
|
|
109
112
|
validate_max(io_size) if @options[:max].present?
|
|
110
113
|
end
|
|
111
114
|
|
|
115
|
+
def boolean
|
|
116
|
+
return if Types::Boolean.valid?(@value)
|
|
117
|
+
|
|
118
|
+
@errors << { message: error_message }
|
|
119
|
+
end
|
|
120
|
+
|
|
112
121
|
def validate_inclusion
|
|
113
122
|
return if @options[:in].include?(@value)
|
|
114
123
|
|
|
@@ -118,6 +127,16 @@ module ValidateParams
|
|
|
118
127
|
}
|
|
119
128
|
end
|
|
120
129
|
|
|
130
|
+
def array_validate_inclusion
|
|
131
|
+
extra_values = Types::Array.cast(@value, **@options) - @options[:in]
|
|
132
|
+
return if extra_values.empty?
|
|
133
|
+
|
|
134
|
+
@errors << {
|
|
135
|
+
message: I18n.t("validate_params.array_invalid_in", param: error_param_name, values: extra_values),
|
|
136
|
+
valid_values: @options[:in]
|
|
137
|
+
}
|
|
138
|
+
end
|
|
139
|
+
|
|
121
140
|
def validate_min(value)
|
|
122
141
|
min_value = @options[:min].is_a?(Proc) ? @options[:min].call : @options[:min]
|
|
123
142
|
return if min_value <= value
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ValidateParams
|
|
4
|
+
class Types
|
|
5
|
+
class Boolean
|
|
6
|
+
TRUE_VALUES = [true, 1, "1", :"1", "t", :t, "T", :T, "true", :true, "TRUE", :TRUE, "on", :on, "ON", :ON].to_set.freeze
|
|
7
|
+
FALSE_VALUES = [false, 0, "0", :"0", "f", :f, "F", :F, "false", :false, "FALSE", :FALSE, "off", :off, "OFF", :OFF].to_set.freeze
|
|
8
|
+
|
|
9
|
+
def self.valid?(value)
|
|
10
|
+
value.is_a?(::TrueClass) || value.is_a?(::FalseClass)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.cast(raw_value, **)
|
|
14
|
+
return true if TRUE_VALUES.include?(raw_value)
|
|
15
|
+
return false if FALSE_VALUES.include?(raw_value)
|
|
16
|
+
|
|
17
|
+
raw_value
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -9,6 +9,7 @@ require "validate_params/types/float"
|
|
|
9
9
|
require "validate_params/types/array"
|
|
10
10
|
require "validate_params/types/string"
|
|
11
11
|
require "validate_params/types/i_o"
|
|
12
|
+
require "validate_params/types/boolean"
|
|
12
13
|
require_relative "param_builder"
|
|
13
14
|
require_relative "param_validator"
|
|
14
15
|
|
|
@@ -129,7 +130,8 @@ module ValidateParams
|
|
|
129
130
|
return if value.blank?
|
|
130
131
|
|
|
131
132
|
options = validation.options.presence || {}
|
|
132
|
-
|
|
133
|
+
type_name = validation.type.is_a?(Symbol) ? validation.type.to_s.classify : validation.type.name
|
|
134
|
+
params[validation.field] = Types.const_get(type_name).cast(value, **options)
|
|
133
135
|
end
|
|
134
136
|
end
|
|
135
137
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: validate-params
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.16.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- dcherevatenko
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionpack
|
|
@@ -117,6 +117,7 @@ files:
|
|
|
117
117
|
- lib/validate_params/param_builder.rb
|
|
118
118
|
- lib/validate_params/param_validator.rb
|
|
119
119
|
- lib/validate_params/types/array.rb
|
|
120
|
+
- lib/validate_params/types/boolean.rb
|
|
120
121
|
- lib/validate_params/types/date.rb
|
|
121
122
|
- lib/validate_params/types/date_time.rb
|
|
122
123
|
- lib/validate_params/types/float.rb
|