validate-params 0.12.1 → 0.12.3

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: 6da9b53b1bcc125e80f19e0a2ba6e3ec9090ce5316202ddcc99472a41f0e77c3
4
- data.tar.gz: c6aa9696e95386c743c3471d1dc4d1f390d44332bf4aee931adb56bdc715bce7
3
+ metadata.gz: 42490d834870ce9c5b7ee67062d1ad59c2066b168f51d7d554e920e25ec758c4
4
+ data.tar.gz: ca97ac17ee9acbdaa75dbbf92fccfd7e71950a2f3fa1b993e22a3064daac9f23
5
5
  SHA512:
6
- metadata.gz: bc0e7388e3e31e70d86319186a0ff3b9e4b31417a1d90e3ee49f5d7308c470960f4eb3c973e68cb31436e5a4fc9e227c26d04ccbdd2918582d80dcd7a439dab0
7
- data.tar.gz: 2c73000905f04bb2a5901a319b62cd13cb7f987b33b66e6382b8a8e6c99f0671eae736d1893ea08a16aaf82b415ad55545975447338e6b61ac007265b5ddc708
6
+ metadata.gz: c3cefceece707a82400448cb82cc20281b151ca665da6b1b27d8b85daa89188a8e686669e0058f68f6690b68224e334d384bb33381ea39a8ffc93c2a53db6495
7
+ data.tar.gz: adba082bd06dff4c1d758de2c84ecfe150e86d8099fcefa7b11f057919a452d4cfa49632332c0f9cfa415c2c9c075a123a62ca0cc687e74fa5b6812459ad1a01
data/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
- ## [Unreleased]
1
+ ## [0.12.3] - 2024-04-14
2
+
3
+ - Default option for Integer type should support empty string as well
2
4
 
3
5
  ## [0.11.0] - 2023-11-04
4
6
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validate-params (0.12.1)
4
+ validate-params (0.12.3)
5
5
  activesupport (>= 6.1.0)
6
6
  i18n (>= 1.6)
7
7
 
@@ -23,6 +23,29 @@ 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
+
26
49
  def validate_params_for(action, options = {})
27
50
  options[:format] ||= :json
28
51
  @params_validations ||= {}
@@ -95,7 +118,12 @@ module ValidateParams
95
118
  return if !options.key?(:default)
96
119
 
97
120
  value = options[:default].is_a?(Proc) ? options[:default].call : options[:default]
98
- params[validation.field] ||= value
121
+
122
+ if validation.type == Integer
123
+ params[validation.field] = value if params[validation.field].blank?
124
+ else
125
+ params[validation.field] ||= value
126
+ end
99
127
  end
100
128
 
101
129
  def cast_param_values(params, validation)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ValidateParams
4
- VERSION = "0.12.1"
4
+ VERSION = "0.12.3"
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.1
4
+ version: 0.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - dcherevatenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-05 00:00:00.000000000 Z
11
+ date: 2024-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack