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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42490d834870ce9c5b7ee67062d1ad59c2066b168f51d7d554e920e25ec758c4
4
- data.tar.gz: ca97ac17ee9acbdaa75dbbf92fccfd7e71950a2f3fa1b993e22a3064daac9f23
3
+ metadata.gz: a0efef56bcd7c8b05e33859d21078422a2a772d3dbb8241a9d0a0e5818c085a6
4
+ data.tar.gz: 23936b451c39e8b6425498c75383b4742ab8e43850f83960aeb200846d59dd32
5
5
  SHA512:
6
- metadata.gz: c3cefceece707a82400448cb82cc20281b151ca665da6b1b27d8b85daa89188a8e686669e0058f68f6690b68224e334d384bb33381ea39a8ffc93c2a53db6495
7
- data.tar.gz: adba082bd06dff4c1d758de2c84ecfe150e86d8099fcefa7b11f057919a452d4cfa49632332c0f9cfa415c2c9c075a123a62ca0cc687e74fa5b6812459ad1a01
6
+ metadata.gz: 963d02b70917dfb1c81dbe672c62ff750c3ed76ae39943eb719e8385b90cf53e588c0d4599cff3551b367650f43a3f0b88cc975a7147e3a3f6f934670f99092f
7
+ data.tar.gz: 1ef4c60aba7a23cff17ad899ebe6996b77312203a0a5c11509dcc53bf66c6cd4801eb03d4af63e5fefcae4ce086de115e919c2e11b15390bd81d9a15c409d7e6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.12.5] - 2024-04-15
2
+
3
+ - Restrict validation rules for Hash type objects
4
+
5
+ ## [0.12.4] - 2024-04-14
6
+
7
+ - Revert 0.12.2 changes
8
+
1
9
  ## [0.12.3] - 2024-04-14
2
10
 
3
11
  - Default option for Integer type should support empty string as well
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validate-params (0.12.3)
4
+ validate-params (0.12.5)
5
5
  activesupport (>= 6.1.0)
6
6
  i18n (>= 1.6)
7
7
 
@@ -14,9 +14,9 @@ module ValidateParams
14
14
  if children.any?
15
15
  case type.to_s
16
16
  when "Hash"
17
- # Skip in case hash is configured and string is passed
18
- if !value.is_a?(String)
19
- children.each { |c| c.valid?(value&.[](c.field), errors) }
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|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ValidateParams
4
- VERSION = "0.12.3"
4
+ VERSION = "0.12.5"
5
5
  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.12.3
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-14 00:00:00.000000000 Z
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.4.10
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: []