validate-params 0.8.1 → 0.9.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 +6 -2
- data/Gemfile +1 -1
- data/Gemfile.lock +12 -9
- data/README.md +4 -4
- data/config/locales/en.yml +2 -0
- data/lib/validate_params/param_validator.rb +38 -4
- data/lib/validate_params/validatable.rb +2 -1
- data/lib/validate_params/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abce4d094f5a56366394cab4c9c01e3bbaca5a9ed5cb3524754d941a7a90d6e6
|
4
|
+
data.tar.gz: 17aa70265348cae7d3f661fa07419da90c4ba1b4b08ccf881baaa5bd556bedf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cd4813db2797307b1e47956f02fffe2358cb7aaa130b5248ac0a8635e32c63a582a190d619af1d5bb5d7e4cf80f590862e97a96edab99c39dbbe86533de833d
|
7
|
+
data.tar.gz: 01dbe50eee3aed0eb9ee06dac9035a5e7c81f9f658cdf84e14fc888913a8ed2842049294f7c8c95ee175fb9c0240c66e5193fc87d8008d2c2cb1fb1691f41f6c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.9.0] - 2023-08-02
|
4
|
+
|
5
|
+
- Add :min and :max options to validate param values for Integer types
|
6
|
+
|
3
7
|
## [0.8.0] - 2023-05-30
|
4
8
|
|
5
9
|
- Added support for passing array of actions into validate_params_for to run on multiple actions
|
@@ -17,9 +21,9 @@
|
|
17
21
|
## [0.5.0] - 2023-05-15
|
18
22
|
|
19
23
|
- Support for Proc as options for default to set param default values
|
20
|
-
|
24
|
+
- Add :in options to validate param values against a list of values for String and Integer types
|
21
25
|
- Updated JSON formats of error messages to be more consistent
|
22
|
-
|
26
|
+
|
23
27
|
## [0.3.0] - 2023-05-12
|
24
28
|
|
25
29
|
- Add required attribute support
|
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.9.0)
|
5
5
|
activesupport (>= 6.1.0)
|
6
6
|
i18n (>= 1.6)
|
7
7
|
|
@@ -36,6 +36,7 @@ GEM
|
|
36
36
|
i18n (1.13.0)
|
37
37
|
concurrent-ruby (~> 1.0)
|
38
38
|
json (2.6.3)
|
39
|
+
language_server-protocol (3.17.0.3)
|
39
40
|
loofah (2.21.1)
|
40
41
|
crass (~> 1.0.2)
|
41
42
|
nokogiri (>= 1.5.9)
|
@@ -45,8 +46,9 @@ GEM
|
|
45
46
|
mini_portile2 (~> 2.8.0)
|
46
47
|
racc (~> 1.4)
|
47
48
|
parallel (1.23.0)
|
48
|
-
parser (3.2.2.
|
49
|
+
parser (3.2.2.3)
|
49
50
|
ast (~> 2.4.1)
|
51
|
+
racc
|
50
52
|
racc (1.6.2)
|
51
53
|
rack (2.2.7)
|
52
54
|
rack-test (2.1.0)
|
@@ -58,8 +60,8 @@ GEM
|
|
58
60
|
loofah (~> 2.19, >= 2.19.1)
|
59
61
|
rainbow (3.1.1)
|
60
62
|
rake (13.0.6)
|
61
|
-
regexp_parser (2.8.
|
62
|
-
rexml (3.2.
|
63
|
+
regexp_parser (2.8.1)
|
64
|
+
rexml (3.2.6)
|
63
65
|
rspec (3.12.0)
|
64
66
|
rspec-core (~> 3.12.0)
|
65
67
|
rspec-expectations (~> 3.12.0)
|
@@ -73,17 +75,18 @@ GEM
|
|
73
75
|
diff-lcs (>= 1.2.0, < 2.0)
|
74
76
|
rspec-support (~> 3.12.0)
|
75
77
|
rspec-support (3.12.0)
|
76
|
-
rubocop (1.
|
78
|
+
rubocop (1.55.1)
|
77
79
|
json (~> 2.3)
|
80
|
+
language_server-protocol (>= 3.17.0)
|
78
81
|
parallel (~> 1.10)
|
79
|
-
parser (>= 3.2.
|
82
|
+
parser (>= 3.2.2.3)
|
80
83
|
rainbow (>= 2.2.2, < 4.0)
|
81
84
|
regexp_parser (>= 1.8, < 3.0)
|
82
85
|
rexml (>= 3.2.5, < 4.0)
|
83
|
-
rubocop-ast (>= 1.28.
|
86
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
84
87
|
ruby-progressbar (~> 1.7)
|
85
88
|
unicode-display_width (>= 2.4.0, < 3.0)
|
86
|
-
rubocop-ast (1.
|
89
|
+
rubocop-ast (1.29.0)
|
87
90
|
parser (>= 3.2.1.0)
|
88
91
|
ruby-progressbar (1.13.0)
|
89
92
|
tzinfo (2.0.6)
|
@@ -99,7 +102,7 @@ DEPENDENCIES
|
|
99
102
|
bundler (~> 2.0)
|
100
103
|
rake (~> 13.0)
|
101
104
|
rspec (~> 3.0)
|
102
|
-
rubocop (~> 1.
|
105
|
+
rubocop (~> 1.55)
|
103
106
|
validate-params!
|
104
107
|
|
105
108
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -29,11 +29,11 @@ class TestController < ActionController::Base
|
|
29
29
|
p.param :user_ids, Array, of: Integer, default: [1, 2, 3]
|
30
30
|
p.param :states, Array, of: String, default: ["active", "inactive"], reject_blank: true
|
31
31
|
p.param :date_of_birth, Hash do |pp|
|
32
|
-
pp.param :gt, Date
|
32
|
+
pp.param :gt, Date, min: Date.new(2020, 1, 1), max: Date.new(2021, 1, 1)
|
33
33
|
pp.param :lt, Date
|
34
34
|
end
|
35
35
|
p.param :created_at, Hash do |pp|
|
36
|
-
pp.param :lt, DateTime
|
36
|
+
pp.param :lt, DateTime, min: DateTime.new(2020, 1, 1), max: DateTime.new(2021, 1, 1)
|
37
37
|
pp.param :gt, DateTime
|
38
38
|
end
|
39
39
|
end
|
@@ -55,7 +55,7 @@ If the parameters are valid, the controller action will be executed as normal. I
|
|
55
55
|
{
|
56
56
|
"message": "hired_on must be a valid Date"
|
57
57
|
},
|
58
|
-
|
58
|
+
|
59
59
|
]
|
60
60
|
}
|
61
61
|
```
|
@@ -64,7 +64,7 @@ If the parameters are valid, the controller action will be executed as normal. I
|
|
64
64
|
|
65
65
|
By default responses are returned in JSON format. To return responses as an empty HTML response, change the :format options in the validate_params methods to :html.
|
66
66
|
|
67
|
-
Example:
|
67
|
+
Example:
|
68
68
|
|
69
69
|
```ruby
|
70
70
|
validate_params :index, format: :html do |p|
|
data/config/locales/en.yml
CHANGED
@@ -36,15 +36,27 @@ module ValidateParams
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def date
|
39
|
-
|
39
|
+
if !Types::Date.valid?(@value)
|
40
|
+
@errors << { message: error_message }
|
41
|
+
return
|
42
|
+
end
|
40
43
|
|
41
|
-
|
44
|
+
formatted_value = Types::Date.cast(@value)
|
45
|
+
|
46
|
+
validate_min(formatted_value) if @options[:min].present?
|
47
|
+
validate_max(formatted_value) if @options[:max].present?
|
42
48
|
end
|
43
49
|
|
44
50
|
def date_time
|
45
|
-
|
51
|
+
if !Types::DateTime.valid?(@value)
|
52
|
+
@errors << { message: error_message }
|
53
|
+
return
|
54
|
+
end
|
46
55
|
|
47
|
-
|
56
|
+
formatted_value = Types::DateTime.cast(@value)
|
57
|
+
|
58
|
+
validate_min(formatted_value) if @options[:min].present?
|
59
|
+
validate_max(formatted_value) if @options[:max].present?
|
48
60
|
end
|
49
61
|
|
50
62
|
def integer
|
@@ -53,7 +65,11 @@ module ValidateParams
|
|
53
65
|
return
|
54
66
|
end
|
55
67
|
|
68
|
+
formatted_value = Types::Integer.cast(@value)
|
69
|
+
|
56
70
|
validate_inclusion if @options[:in].present?
|
71
|
+
validate_min(formatted_value) if @options[:min].present?
|
72
|
+
validate_max(formatted_value) if @options[:max].present?
|
57
73
|
end
|
58
74
|
|
59
75
|
def string
|
@@ -69,6 +85,24 @@ module ValidateParams
|
|
69
85
|
}
|
70
86
|
end
|
71
87
|
|
88
|
+
def validate_min(value)
|
89
|
+
return if @options[:min] <= value
|
90
|
+
|
91
|
+
@errors << {
|
92
|
+
message: I18n.t("validate_params.less_than_min", param: error_param_name),
|
93
|
+
min: @options[:min]
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
def validate_max(value)
|
98
|
+
return if @options[:max] >= value
|
99
|
+
|
100
|
+
@errors << {
|
101
|
+
message: I18n.t("validate_params.more_than_max", param: error_param_name),
|
102
|
+
max: @options[:max]
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
72
106
|
def error_param_name
|
73
107
|
case @field
|
74
108
|
when Array
|
@@ -4,6 +4,7 @@ require "validate_params/types/date"
|
|
4
4
|
require "validate_params/types/date_time"
|
5
5
|
require "validate_params/types/integer"
|
6
6
|
require "validate_params/types/array"
|
7
|
+
require "validate_params/types/string"
|
7
8
|
require_relative "param_builder"
|
8
9
|
require_relative "param_validator"
|
9
10
|
|
@@ -25,7 +26,7 @@ module ValidateParams
|
|
25
26
|
@params_validations ||= {}
|
26
27
|
|
27
28
|
Array(action).each do |act|
|
28
|
-
@params_validations[act] ||= {options: options, validations: []}
|
29
|
+
@params_validations[act] ||= { options: options, validations: [] }
|
29
30
|
|
30
31
|
yield(ParamBuilder.new(validations: @params_validations[act][:validations])) if block
|
31
32
|
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.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dcherevatenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|