validate-params 0.5.0 → 0.5.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/Gemfile +1 -1
- data/Gemfile.lock +3 -3
- data/README.md +3 -2
- data/lib/validate_params/params_validator.rb +19 -11
- data/lib/validate_params/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cc4a4179e78c2c12842ddac40a4745028bbbf7f5f90cc0031fcaa3ae5db1422
|
4
|
+
data.tar.gz: 33e7a943d361d305a14e1a4c6f0d97f8f20f078d89ee872857238db5b947ab90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d081f19216d1a04527a13366857f37a25c818398dffa4703540b4f806593942d75d6759b4a8892fc2512dd72fa6a882d3a5ef7f9b57ac178b6c160b5d26896f
|
7
|
+
data.tar.gz: c484a35d91d3b3d3ff7c96b301063bb497e25dfea5621b3db3ade98b36a5981cae8555b451eff9d9b8240a579826b762f91025a5f86859d4e33476e9325ccd86
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
validate-params (0.5.
|
4
|
+
validate-params (0.5.1)
|
5
5
|
activesupport (>= 6.1.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -72,7 +72,7 @@ GEM
|
|
72
72
|
diff-lcs (>= 1.2.0, < 2.0)
|
73
73
|
rspec-support (~> 3.12.0)
|
74
74
|
rspec-support (3.12.0)
|
75
|
-
rubocop (1.
|
75
|
+
rubocop (1.51.0)
|
76
76
|
json (~> 2.3)
|
77
77
|
parallel (~> 1.10)
|
78
78
|
parser (>= 3.2.0.0)
|
@@ -98,7 +98,7 @@ DEPENDENCIES
|
|
98
98
|
bundler (~> 2.0)
|
99
99
|
rake (~> 13.0)
|
100
100
|
rspec (~> 3.0)
|
101
|
-
rubocop (~> 1.
|
101
|
+
rubocop (~> 1.51)
|
102
102
|
validate-params!
|
103
103
|
|
104
104
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -23,8 +23,9 @@ class TestController < ActionController::Base
|
|
23
23
|
include ValidateParams::ParamsValidator
|
24
24
|
|
25
25
|
validate_params :index do |p|
|
26
|
-
p.param :
|
27
|
-
p.param :
|
26
|
+
p.param :name, String, default: "John Doe"
|
27
|
+
p.param :occurred_on, Date, required: true, default: proc { Date.today }
|
28
|
+
p.param :quantity, Integer, required: true, in: [1, 2, 3]
|
28
29
|
p.param :date_of_birth, Hash do |pp|
|
29
30
|
pp.param :gt, Date
|
30
31
|
pp.param :lt, Date
|
@@ -14,12 +14,13 @@ module ValidateParams
|
|
14
14
|
|
15
15
|
def param(field, type, options = {}, &block)
|
16
16
|
@params_validations ||= []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
|
18
|
+
if block
|
19
|
+
param_builder = ParamBuilder.new(field)
|
20
|
+
@params_validations += yield(param_builder)
|
21
|
+
else
|
22
|
+
@params_validations << ParamBuilder.new.param(field, type, options)
|
23
|
+
end
|
23
24
|
end
|
24
25
|
|
25
26
|
def validate_params_for(request_action, &block)
|
@@ -64,6 +65,8 @@ module ValidateParams
|
|
64
65
|
|
65
66
|
if params_validation[:field].is_a?(Hash)
|
66
67
|
params_validation[:field].each_key do |key|
|
68
|
+
# Skip in case hash is configured and string is passed
|
69
|
+
next if params.dig(key).is_a? Hash
|
67
70
|
next if params.dig(key, params_validation[:field][key])
|
68
71
|
|
69
72
|
value = if params_validation[:options][:default].is_a?(Proc)
|
@@ -91,6 +94,10 @@ module ValidateParams
|
|
91
94
|
errors = []
|
92
95
|
|
93
96
|
for params_validation in params_validations
|
97
|
+
# Skip in case hash is configured and string is passed
|
98
|
+
next if params_validation[:field].is_a?(Hash) &&
|
99
|
+
params.dig(params_validation[:field].keys.first).is_a?(String)
|
100
|
+
|
94
101
|
parameter_value = if params_validation[:field].is_a? Hash
|
95
102
|
params.dig(params_validation[:field].keys.first,
|
96
103
|
params_validation[:field][params_validation[:field].keys.first])
|
@@ -174,15 +181,16 @@ module ValidateParams
|
|
174
181
|
class ParamBuilder
|
175
182
|
def initialize(parent_field = nil)
|
176
183
|
@parent_field = parent_field
|
184
|
+
@params_validations = []
|
177
185
|
end
|
178
186
|
|
179
187
|
def param(field, type, options = {})
|
180
|
-
|
181
|
-
|
182
|
-
{ field: { @parent_field => field }, type: type, options: options }
|
183
|
-
else
|
184
|
-
{ field: field, type: type, options: options }
|
188
|
+
unless @parent_field
|
189
|
+
return { field: field, type: type, options: options }
|
185
190
|
end
|
191
|
+
|
192
|
+
@params_validations << { field: { @parent_field => field }, type: type, options: options }
|
193
|
+
@params_validations
|
186
194
|
end
|
187
195
|
end
|
188
196
|
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validate-params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dcherevatenko
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
date: 2023-05-15 00:00:00.000000000 Z
|
@@ -100,11 +100,11 @@ files:
|
|
100
100
|
- lib/validate_params/version.rb
|
101
101
|
- sig/validate_params.rbs
|
102
102
|
- validate_params.gemspec
|
103
|
-
homepage:
|
103
|
+
homepage:
|
104
104
|
licenses:
|
105
105
|
- MIT
|
106
106
|
metadata: {}
|
107
|
-
post_install_message:
|
107
|
+
post_install_message:
|
108
108
|
rdoc_options: []
|
109
109
|
require_paths:
|
110
110
|
- lib
|
@@ -119,8 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
- !ruby/object:Gem::Version
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
|
-
rubygems_version: 3.
|
123
|
-
signing_key:
|
122
|
+
rubygems_version: 3.2.3
|
123
|
+
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: Gem to validate params in controllers
|
126
126
|
test_files: []
|