validate-params 0.12.3 → 0.12.5
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 +8 -0
- data/Gemfile.lock +1 -1
- data/lib/validate_params/param_builder.rb +3 -3
- data/lib/validate_params/param_validator.rb +6 -0
- data/lib/validate_params/validatable.rb +0 -29
- data/lib/validate_params/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0efef56bcd7c8b05e33859d21078422a2a772d3dbb8241a9d0a0e5818c085a6
|
4
|
+
data.tar.gz: 23936b451c39e8b6425498c75383b4742ab8e43850f83960aeb200846d59dd32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 963d02b70917dfb1c81dbe672c62ff750c3ed76ae39943eb719e8385b90cf53e588c0d4599cff3551b367650f43a3f0b88cc975a7147e3a3f6f934670f99092f
|
7
|
+
data.tar.gz: 1ef4c60aba7a23cff17ad899ebe6996b77312203a0a5c11509dcc53bf66c6cd4801eb03d4af63e5fefcae4ce086de115e919c2e11b15390bd81d9a15c409d7e6
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -14,9 +14,9 @@ module ValidateParams
|
|
14
14
|
if children.any?
|
15
15
|
case type.to_s
|
16
16
|
when "Hash"
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
children.each do |child|
|
18
|
+
child_value = value[child.field] if value.is_a?(Hash) || value.is_a?(ActionController::Parameters)
|
19
|
+
child.valid?(child_value, errors)
|
20
20
|
end
|
21
21
|
when "Array"
|
22
22
|
values = value ? Array.wrap(value) : [nil]
|
@@ -30,6 +30,12 @@ module ValidateParams
|
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
33
|
+
def hash
|
34
|
+
return if @value.is_a?(Hash) || @value.is_a?(ActionController::Parameters)
|
35
|
+
|
36
|
+
@errors << { message: error_message }
|
37
|
+
end
|
38
|
+
|
33
39
|
def array
|
34
40
|
return if Types::Array.valid?(@value, **@options)
|
35
41
|
|
@@ -23,29 +23,6 @@ module ValidateParams
|
|
23
23
|
class_methods do
|
24
24
|
attr_reader :params_validations
|
25
25
|
|
26
|
-
# When controller inherits from other controller, we need to copy the validations.
|
27
|
-
#
|
28
|
-
# Usage example:
|
29
|
-
#
|
30
|
-
# class ParentController < ApplicationController
|
31
|
-
# validate_params_for :index do |p|
|
32
|
-
# p.param :param1, Integer, min: 1, max: 10
|
33
|
-
# p.param :param2, Integer, min: 10, max: 20
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
# class ChildController < ParentController
|
38
|
-
# validate_params_for :index do |p|
|
39
|
-
# p.param :param1, Integer, min: 0, max: 5
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
#
|
43
|
-
# Here in ChildController, the param1 validation will be overridden, but validation for param2 will remain unchanged.
|
44
|
-
#
|
45
|
-
def inherited(child)
|
46
|
-
child.instance_variable_set("@params_validations", @params_validations.deep_dup)
|
47
|
-
end
|
48
|
-
|
49
26
|
def validate_params_for(action, options = {})
|
50
27
|
options[:format] ||= :json
|
51
28
|
@params_validations ||= {}
|
@@ -102,9 +79,6 @@ module ValidateParams
|
|
102
79
|
apply_default_values(sub_params, sub_validation)
|
103
80
|
end
|
104
81
|
elsif validation.type == Hash
|
105
|
-
# Skip in case hash is configured and string is passed
|
106
|
-
next if params[validation.field].is_a?(String)
|
107
|
-
|
108
82
|
params[validation.field] ||= {}
|
109
83
|
apply_default_values(params[validation.field], sub_validation)
|
110
84
|
else
|
@@ -131,9 +105,6 @@ module ValidateParams
|
|
131
105
|
|
132
106
|
validation.children.each do |sub_validation|
|
133
107
|
if validation.type == Hash
|
134
|
-
# Skip in case hash is configured and string is passed
|
135
|
-
next if params[validation.field].is_a?(String)
|
136
|
-
|
137
108
|
cast_param_values(params[validation.field], sub_validation)
|
138
109
|
elsif validation.type == Array
|
139
110
|
params[validation.field].each do |sub_params|
|
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.12.
|
4
|
+
version: 0.12.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dcherevatenko
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -124,11 +124,11 @@ files:
|
|
124
124
|
- lib/validate_params/version.rb
|
125
125
|
- sig/validate_params.rbs
|
126
126
|
- validate_params.gemspec
|
127
|
-
homepage:
|
127
|
+
homepage:
|
128
128
|
licenses:
|
129
129
|
- MIT
|
130
130
|
metadata: {}
|
131
|
-
post_install_message:
|
131
|
+
post_install_message:
|
132
132
|
rdoc_options: []
|
133
133
|
require_paths:
|
134
134
|
- lib
|
@@ -143,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
146
|
+
rubygems_version: 3.3.26
|
147
|
+
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: Gem to validate params in controllers
|
150
150
|
test_files: []
|