validate-params 0.10.0 → 0.11.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 +5 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +8 -10
- data/README.md +3 -1
- data/lib/validate_params/param_validator.rb +16 -3
- data/lib/validate_params/types/array.rb +10 -2
- data/lib/validate_params/types/float.rb +15 -0
- data/lib/validate_params/types/i_o.rb +3 -1
- data/lib/validate_params/validatable.rb +1 -0
- data/lib/validate_params/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40dd463b2500f9e2ab704d35c033763aaf80299e71796104889cc5850aaa1c50
|
4
|
+
data.tar.gz: f0ba27d4568a6dab4e3770cd967085654701fcdd24d74e15519e2d5302c5dce0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c9b40b0a3f57659b9b5c86713888d0ef8d294bbe21505cc065a406548e032626d1a625a72e72236a895dddc9ea03288c62668de03b437d06d0f1c67f76fc467
|
7
|
+
data.tar.gz: 728615aee1a6082e3816bde334fa064ef7462a9bef9833f029d330ebd98409807a367988def4f4c5c984a2afecdd80e2839296ecf12f351c7647d1a0a54f8434
|
data/CHANGELOG.md
CHANGED
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.11.0)
|
5
5
|
activesupport (>= 6.1.0)
|
6
6
|
i18n (>= 1.6)
|
7
7
|
|
@@ -28,7 +28,6 @@ GEM
|
|
28
28
|
tzinfo (~> 2.0)
|
29
29
|
zeitwerk (~> 2.3)
|
30
30
|
ast (2.4.2)
|
31
|
-
base64 (0.1.1)
|
32
31
|
builder (3.2.4)
|
33
32
|
concurrent-ruby (1.2.2)
|
34
33
|
crass (1.0.6)
|
@@ -47,7 +46,7 @@ GEM
|
|
47
46
|
mini_portile2 (~> 2.8.0)
|
48
47
|
racc (~> 1.4)
|
49
48
|
parallel (1.23.0)
|
50
|
-
parser (3.2.2.
|
49
|
+
parser (3.2.2.4)
|
51
50
|
ast (~> 2.4.1)
|
52
51
|
racc
|
53
52
|
racc (1.7.1)
|
@@ -61,7 +60,7 @@ GEM
|
|
61
60
|
loofah (~> 2.19, >= 2.19.1)
|
62
61
|
rainbow (3.1.1)
|
63
62
|
rake (13.0.6)
|
64
|
-
regexp_parser (2.8.
|
63
|
+
regexp_parser (2.8.2)
|
65
64
|
rexml (3.2.6)
|
66
65
|
rspec (3.12.0)
|
67
66
|
rspec-core (~> 3.12.0)
|
@@ -76,24 +75,23 @@ GEM
|
|
76
75
|
diff-lcs (>= 1.2.0, < 2.0)
|
77
76
|
rspec-support (~> 3.12.0)
|
78
77
|
rspec-support (3.12.0)
|
79
|
-
rubocop (1.
|
80
|
-
base64 (~> 0.1.1)
|
78
|
+
rubocop (1.57.2)
|
81
79
|
json (~> 2.3)
|
82
80
|
language_server-protocol (>= 3.17.0)
|
83
81
|
parallel (~> 1.10)
|
84
|
-
parser (>= 3.2.2.
|
82
|
+
parser (>= 3.2.2.4)
|
85
83
|
rainbow (>= 2.2.2, < 4.0)
|
86
84
|
regexp_parser (>= 1.8, < 3.0)
|
87
85
|
rexml (>= 3.2.5, < 4.0)
|
88
86
|
rubocop-ast (>= 1.28.1, < 2.0)
|
89
87
|
ruby-progressbar (~> 1.7)
|
90
88
|
unicode-display_width (>= 2.4.0, < 3.0)
|
91
|
-
rubocop-ast (1.
|
89
|
+
rubocop-ast (1.30.0)
|
92
90
|
parser (>= 3.2.1.0)
|
93
91
|
ruby-progressbar (1.13.0)
|
94
92
|
tzinfo (2.0.6)
|
95
93
|
concurrent-ruby (~> 1.0)
|
96
|
-
unicode-display_width (2.
|
94
|
+
unicode-display_width (2.5.0)
|
97
95
|
zeitwerk (2.6.8)
|
98
96
|
|
99
97
|
PLATFORMS
|
@@ -104,7 +102,7 @@ DEPENDENCIES
|
|
104
102
|
bundler (~> 2.0)
|
105
103
|
rake (~> 13.0)
|
106
104
|
rspec (~> 3.0)
|
107
|
-
rubocop (~> 1.
|
105
|
+
rubocop (~> 1.57)
|
108
106
|
validate-params!
|
109
107
|
|
110
108
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -27,6 +27,7 @@ class TestController < ActionController::Base
|
|
27
27
|
p.param :occurred_on, Date, required: true, default: proc { Date.today }
|
28
28
|
p.param :per_page, Integer, default: 50, min: 1, max: 50
|
29
29
|
p.param :quantity, Integer, required: true, in: [1, 2, 3]
|
30
|
+
p.param :weight, Float
|
30
31
|
p.param :user_ids, Array, of: Integer, default: [1, 2, 3]
|
31
32
|
p.param :states, Array, of: String, default: ["active", "inactive"], reject_blank: true
|
32
33
|
p.param :file, IO, min: 1.byte, max: 1.megabyte
|
@@ -52,10 +53,11 @@ Here are the following supported types along with operations supported.
|
|
52
53
|
|
53
54
|
- String (required, default)
|
54
55
|
- Integer (required, default, min, max, in)
|
56
|
+
- Float (required, default, min, max, in)
|
55
57
|
- Date (required, default, min, max)
|
56
58
|
- DateTime (required, default, min, max)
|
57
59
|
- IO (required, min, max)
|
58
|
-
- Array of: (String|Integer) (default, reject_blank)
|
60
|
+
- Array of: (String|Integer|Float) (default, reject_blank)
|
59
61
|
- Hash - Nested block of types
|
60
62
|
|
61
63
|
|
@@ -72,6 +72,19 @@ module ValidateParams
|
|
72
72
|
validate_max(formatted_value) if @options[:max].present?
|
73
73
|
end
|
74
74
|
|
75
|
+
def float
|
76
|
+
unless Types::Float.valid?(@value)
|
77
|
+
@errors << { message: error_message }
|
78
|
+
return
|
79
|
+
end
|
80
|
+
|
81
|
+
formatted_value = Types::Float.cast(@value)
|
82
|
+
|
83
|
+
validate_inclusion if @options[:in].present?
|
84
|
+
validate_min(formatted_value) if @options[:min].present?
|
85
|
+
validate_max(formatted_value) if @options[:max].present?
|
86
|
+
end
|
87
|
+
|
75
88
|
def string
|
76
89
|
validate_inclusion if @options[:in].present?
|
77
90
|
end
|
@@ -82,10 +95,10 @@ module ValidateParams
|
|
82
95
|
return
|
83
96
|
end
|
84
97
|
|
85
|
-
|
98
|
+
io_size = @value.size
|
86
99
|
|
87
|
-
validate_min(
|
88
|
-
validate_max(
|
100
|
+
validate_min(io_size) if @options[:min].present?
|
101
|
+
validate_max(io_size) if @options[:max].present?
|
89
102
|
end
|
90
103
|
|
91
104
|
def validate_inclusion
|
@@ -4,12 +4,18 @@ module ValidateParams
|
|
4
4
|
class Types
|
5
5
|
class Array
|
6
6
|
def self.valid?(value, of: String, reject_blank: false, **)
|
7
|
+
return false unless value.is_a?(::Array)
|
8
|
+
|
7
9
|
val = value
|
8
|
-
val
|
10
|
+
val.reject!(&:blank?) if reject_blank
|
9
11
|
|
10
12
|
case of.to_s
|
11
13
|
when "Integer"
|
12
14
|
val.all? { |item| Types::Integer.valid?(item) }
|
15
|
+
when "Float"
|
16
|
+
val.all? { |item| Types::Float.valid?(item) }
|
17
|
+
when "String"
|
18
|
+
val.all? { |item| item.is_a?(::String) }
|
13
19
|
else
|
14
20
|
true
|
15
21
|
end
|
@@ -17,11 +23,13 @@ module ValidateParams
|
|
17
23
|
|
18
24
|
def self.cast(raw_value, of: String, reject_blank: false, **)
|
19
25
|
value = raw_value
|
20
|
-
value
|
26
|
+
value.reject!(&:blank?) if reject_blank
|
21
27
|
|
22
28
|
case of.to_s
|
23
29
|
when "Integer"
|
24
30
|
value.map { |item| Types::Integer.cast(item) }
|
31
|
+
when "Float"
|
32
|
+
value.map { |item| Types::Float.cast(item) }
|
25
33
|
else
|
26
34
|
value
|
27
35
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require "validate_params/types/date"
|
4
4
|
require "validate_params/types/date_time"
|
5
5
|
require "validate_params/types/integer"
|
6
|
+
require "validate_params/types/float"
|
6
7
|
require "validate_params/types/array"
|
7
8
|
require "validate_params/types/string"
|
8
9
|
require "validate_params/types/i_o"
|
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.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dcherevatenko
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/validate_params/types/array.rb
|
117
117
|
- lib/validate_params/types/date.rb
|
118
118
|
- lib/validate_params/types/date_time.rb
|
119
|
+
- lib/validate_params/types/float.rb
|
119
120
|
- lib/validate_params/types/i_o.rb
|
120
121
|
- lib/validate_params/types/integer.rb
|
121
122
|
- lib/validate_params/types/string.rb
|
@@ -123,11 +124,11 @@ files:
|
|
123
124
|
- lib/validate_params/version.rb
|
124
125
|
- sig/validate_params.rbs
|
125
126
|
- validate_params.gemspec
|
126
|
-
homepage:
|
127
|
+
homepage:
|
127
128
|
licenses:
|
128
129
|
- MIT
|
129
130
|
metadata: {}
|
130
|
-
post_install_message:
|
131
|
+
post_install_message:
|
131
132
|
rdoc_options: []
|
132
133
|
require_paths:
|
133
134
|
- lib
|
@@ -142,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
143
|
- !ruby/object:Gem::Version
|
143
144
|
version: '0'
|
144
145
|
requirements: []
|
145
|
-
rubygems_version: 3.
|
146
|
-
signing_key:
|
146
|
+
rubygems_version: 3.4.10
|
147
|
+
signing_key:
|
147
148
|
specification_version: 4
|
148
149
|
summary: Gem to validate params in controllers
|
149
150
|
test_files: []
|