validate-params 0.14.0 → 0.15.1
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.lock +1 -3
- data/README.md +2 -0
- data/lib/validate_params/param_validator.rb +6 -0
- data/lib/validate_params/types/boolean.rb +21 -0
- data/lib/validate_params/types/date_time.rb +3 -1
- data/lib/validate_params/types/string.rb +1 -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: 60d5a946fa5aa5e37911a20e0e58da17dad0e4de72c3daddfb3eb61176aa96ad
|
|
4
|
+
data.tar.gz: 8115804497bd2bfc46db0d489a361521c878922f6aa53c2cf4b373ce4eb11ff1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b28cc35797e7b0f75bc60e8defe55313056f30b6651a29055e62f058d702ab72e3bb0ea6b016162eea8f7426239adf6c7bb0dd3e37c99ca5b0393ebaf5b902b5
|
|
7
|
+
data.tar.gz: e24c5f808855274cf47ddab2160af5e24203909520d88be40c1b6b78ced65e26259c116fa5a7908b4da81e187d1b1bd18139489778df1b49544e03dd11916042
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [0.15.1] - 2025-10-14
|
|
2
|
+
|
|
3
|
+
- Fixed issue with DateTime type validation to reject timestamps that result in years greater than 9999
|
|
4
|
+
|
|
5
|
+
## [0.15.0] - 2025-09-26
|
|
6
|
+
|
|
7
|
+
- Support for boolean type has been added
|
|
8
|
+
|
|
9
|
+
## [0.14.1] - 2025-07-15
|
|
10
|
+
|
|
11
|
+
- Fixed issue with `scrub_invalid_utf8` option in String type to ensure it works correctly with non-string inputs
|
|
12
|
+
|
|
1
13
|
## [0.14.0] - 2024-09-25
|
|
2
14
|
|
|
3
15
|
- Support for Proc as options for `:min` and `:max` to validate param values
|
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.15.1)
|
|
5
5
|
activesupport (>= 6.1.0)
|
|
6
6
|
i18n (>= 1.6)
|
|
7
7
|
|
|
@@ -62,7 +62,6 @@ GEM
|
|
|
62
62
|
rake (13.2.1)
|
|
63
63
|
regexp_parser (2.9.0)
|
|
64
64
|
rexml (3.2.8)
|
|
65
|
-
strscan (>= 3.0.9)
|
|
66
65
|
rspec (3.13.0)
|
|
67
66
|
rspec-core (~> 3.13.0)
|
|
68
67
|
rspec-expectations (~> 3.13.0)
|
|
@@ -90,7 +89,6 @@ GEM
|
|
|
90
89
|
rubocop-ast (1.31.2)
|
|
91
90
|
parser (>= 3.3.0.4)
|
|
92
91
|
ruby-progressbar (1.13.0)
|
|
93
|
-
strscan (3.1.0)
|
|
94
92
|
tzinfo (2.0.6)
|
|
95
93
|
concurrent-ruby (~> 1.0)
|
|
96
94
|
unicode-display_width (2.5.0)
|
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
|
|
@@ -109,6 +109,12 @@ module ValidateParams
|
|
|
109
109
|
validate_max(io_size) if @options[:max].present?
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
+
def boolean
|
|
113
|
+
return if Types::Boolean.valid?(@value)
|
|
114
|
+
|
|
115
|
+
@errors << { message: error_message }
|
|
116
|
+
end
|
|
117
|
+
|
|
112
118
|
def validate_inclusion
|
|
113
119
|
return if @options[:in].include?(@value)
|
|
114
120
|
|
|
@@ -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.15.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- dcherevatenko
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-10-16 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
|