stronger_parameters 2.17.0 → 2.20.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29a714a242ff378f5bf21a4a131c2c1e985e07d99a6698ec74a9c09009d201c6
4
- data.tar.gz: eb48fa058692ca09457c04f2dd29ddb0addeb90cf40d17496c1eb62f7b2a53b3
3
+ metadata.gz: f186917c03263aba1f50d3e3ac7ff3acd4926655f8e9112b7385b34918fdb099
4
+ data.tar.gz: 863fc50ff7e443536ad62de00470439b3b4cfa4288174100db0e154bba9064c9
5
5
  SHA512:
6
- metadata.gz: bc0642f85f672bf56faf7e139e1ea895206a6985f7b8b7a4c5034e1bd023696af0796307fa478007c462c39f2d3dc47fdc769269990e4b0c5be51691709e0d54
7
- data.tar.gz: 133a07b885c0a2d7612e5a8b46c9c53b05534a9be921738a571f910ea6de9c166bebb1891640537e707aa5c6b96fec234cddccde2a860b03d6e0cbff9d5da3d6
6
+ metadata.gz: ccafbf30f5050cc5eb2f3d9340d295197cffe2e183e382a2c16f3acd291f4529695ed5ef110fa742f9e19e3ce6ab950fa8a4364fc5557808c16b3635791a8418
7
+ data.tar.gz: b1bbeb6bb9368094ed661f35eb2d4fbabe719ee81e004b7a6abf40b2dd7d45de4904a1d2ebd52ed780ba230c2c50db6e094a7f50b0cdeb6a009de4ca045e1b91
data/README.md CHANGED
@@ -240,7 +240,6 @@ curl -I 'http://localhost/api/users/1.json' -X POST -d '{ "user": { "id": 1 } }'
240
240
  => X-StrongerParameters-API-Warn: Removed restricted keys ["user.id"] from parameters
241
241
  ```
242
242
 
243
-
244
243
  ## Types
245
244
 
246
245
  | Syntax | (Simplified) Definition |
@@ -248,6 +247,10 @@ curl -I 'http://localhost/api/users/1.json' -X POST -d '{ "user": { "id": 1 } }'
248
247
  | Parameters.string | value.is_a?(String) |
249
248
  | Parameters.integer | value.is_a?(Fixnum) or '-1' |
250
249
  | Parameters.float | value.is_a?(Float) or '-1.2' |
250
+ | Parameters.date | value.is_a?(Date) or '2014-05-13' or '13.05.2014' |
251
+ | Parameters.date_iso8601 | value is a date that conforms to ISO8601: '2014-05-13' |
252
+ | Parameters.time | value.is_a?(Time) or '2014-05-13' or '2015-03-31 14:34:56 +0000' |
253
+ | Parameters.time_iso8601 | value is a time that conforms to ISO8601: '2014-05-13' or '2015-03-31T14:34:56Z' |
251
254
  | Parameters.datetime | value.is_a?(DateTime) or '2014-05-13' or '2015-03-31T14:34:56Z' |
252
255
  | Parameters.datetime_iso8601 | value is a date that conforms to ISO8601: '2014-05-13' or '2015-03-31T14:34:56Z' |
253
256
  | Parameters.regexp(/foo/) | value =~ regexp |
@@ -268,3 +271,16 @@ curl -I 'http://localhost/api/users/1.json' -X POST -d '{ "user": { "id": 1 } }'
268
271
  | Parameters.file | File, StringIO, Rack::Test::UploadedFile, ActionDispatch::Http::UploadedFile or subclasses |
269
272
  | Parameters.decimal(8,2) | value is a String, Integer or Float with a precision of 9 and scale of 2 |
270
273
  | Parameters.hex | value is a String that matches the hexadecimal format |
274
+ | Parameters.ulid | value is a String of length 26 with only Crockford Base32 symbols |
275
+
276
+ ## Development
277
+
278
+ ### Releasing a new version
279
+
280
+ ```
281
+ git checkout master && git fetch origin && git reset --hard origin/master
282
+ bundle exec rake bump:<patch|minor|major>
283
+ bundle exec rake release
284
+ ```
285
+
286
+ [github action](.github/workflows/ruby-gem-publication.yml) will release a new version to rubygems.org
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ require 'stronger_parameters/constraint'
3
+
4
+ module StrongerParameters
5
+ class DateConstraint < Constraint
6
+ def value(v)
7
+ return v if v.is_a?(Date)
8
+
9
+ begin
10
+ Date.parse v
11
+ rescue ArgumentError, TypeError
12
+ StrongerParameters::InvalidValue.new(v, "must be a date")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ require 'stronger_parameters/constraint'
3
+
4
+ module StrongerParameters
5
+ class DateIso8601Constraint < Constraint
6
+ def value(v)
7
+ Date.iso8601 v
8
+ rescue ArgumentError, TypeError
9
+ StrongerParameters::InvalidValue.new(v, "must be an iso8601 date")
10
+ end
11
+ end
12
+ end
@@ -9,7 +9,7 @@ module StrongerParameters
9
9
  begin
10
10
  DateTime.parse v
11
11
  rescue ArgumentError, TypeError
12
- StrongerParameters::InvalidValue.new(v, "must be a date")
12
+ StrongerParameters::InvalidValue.new(v, "must be a datetime")
13
13
  end
14
14
  end
15
15
  end
@@ -6,7 +6,7 @@ module StrongerParameters
6
6
  def value(v)
7
7
  DateTime.iso8601 v
8
8
  rescue ArgumentError, TypeError
9
- StrongerParameters::InvalidValue.new(v, "must be an iso8601 date")
9
+ StrongerParameters::InvalidValue.new(v, "must be an iso8601 datetime")
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ require 'stronger_parameters/constraint'
3
+
4
+ module StrongerParameters
5
+ class TimeConstraint < Constraint
6
+ def value(v)
7
+ return v if v.is_a?(Time)
8
+
9
+ begin
10
+ Time.parse v
11
+ rescue ArgumentError, TypeError
12
+ StrongerParameters::InvalidValue.new(v, "must be a time")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ require 'stronger_parameters/constraint'
3
+
4
+ module StrongerParameters
5
+ class TimeIso8601Constraint < Constraint
6
+ def value(v)
7
+ Time.iso8601 v
8
+ rescue ArgumentError, TypeError
9
+ StrongerParameters::InvalidValue.new(v, "must be an iso8601 time")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require 'stronger_parameters/constraint'
3
+
4
+ module StrongerParameters
5
+ class UlidConstraint < Constraint
6
+ # https://www.crockford.com/base32.html
7
+ INVALID_CHAR_REGEX = /[ilou]|[^a-z0-9]/i.freeze
8
+ ULID_LENGTH = 26
9
+
10
+ def value(v)
11
+ return invalid_value(v) unless v.is_a?(String)
12
+ return invalid_value(v) unless v.length == ULID_LENGTH
13
+ return invalid_value(v) if v =~ INVALID_CHAR_REGEX
14
+
15
+ v
16
+ end
17
+
18
+ private
19
+
20
+ def invalid_value(v)
21
+ StrongerParameters::InvalidValue.new(v, "must be a ULID")
22
+ end
23
+ end
24
+ end
@@ -2,6 +2,10 @@
2
2
  require 'stronger_parameters/constraint'
3
3
  require 'stronger_parameters/constraints/string_constraint'
4
4
  require 'stronger_parameters/constraints/float_constraint'
5
+ require 'stronger_parameters/constraints/date_constraint'
6
+ require 'stronger_parameters/constraints/date_iso8601_constraint'
7
+ require 'stronger_parameters/constraints/time_constraint'
8
+ require 'stronger_parameters/constraints/time_iso8601_constraint'
5
9
  require 'stronger_parameters/constraints/date_time_constraint'
6
10
  require 'stronger_parameters/constraints/date_time_iso8601_constraint'
7
11
  require 'stronger_parameters/constraints/regexp_constraint'
@@ -16,3 +20,4 @@ require 'stronger_parameters/constraints/nil_string_constraint'
16
20
  require 'stronger_parameters/constraints/file_constraint'
17
21
  require 'stronger_parameters/constraints/decimal_constraint'
18
22
  require 'stronger_parameters/constraints/hex_constraint'
23
+ require 'stronger_parameters/constraints/ulid_constraint'
@@ -105,6 +105,22 @@ module StrongerParameters
105
105
  NilStringConstraint.new
106
106
  end
107
107
 
108
+ def date
109
+ DateConstraint.new
110
+ end
111
+
112
+ def date_iso8601
113
+ DateIso8601Constraint.new
114
+ end
115
+
116
+ def time
117
+ TimeConstraint.new
118
+ end
119
+
120
+ def time_iso8601
121
+ TimeIso8601Constraint.new
122
+ end
123
+
108
124
  def datetime
109
125
  DateTimeConstraint.new
110
126
  end
@@ -124,6 +140,10 @@ module StrongerParameters
124
140
  def hex
125
141
  HexConstraint.new
126
142
  end
143
+
144
+ def ulid
145
+ UlidConstraint.new
146
+ end
127
147
  end
128
148
 
129
149
  def hash_filter_with_stronger_parameters(params, filter)
@@ -160,7 +180,7 @@ module StrongerParameters
160
180
 
161
181
  if result.is_a?(InvalidValue)
162
182
  name = "invalid_parameter.action_controller"
163
- ActiveSupport::Notifications.publish(name, key: key, value: value, message: result.message)
183
+ ActiveSupport::Notifications.instrument(name, key: key, value: value, message: result.message)
164
184
 
165
185
  action = self.class.action_on_invalid_parameters
166
186
  case action
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module StrongerParameters
3
- VERSION = '2.17.0'
3
+ VERSION = '2.20.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stronger_parameters
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.17.0
4
+ version: 2.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mick Staugaard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-10 00:00:00.000000000 Z
11
+ date: 2023-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,20 +108,6 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: mocha
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: forking_test_runner
127
113
  requirement: !ruby/object:Gem::Requirement
@@ -170,6 +156,8 @@ files:
170
156
  - lib/stronger_parameters/constraints/array_constraint.rb
171
157
  - lib/stronger_parameters/constraints/boolean_constraint.rb
172
158
  - lib/stronger_parameters/constraints/comparison_constraints.rb
159
+ - lib/stronger_parameters/constraints/date_constraint.rb
160
+ - lib/stronger_parameters/constraints/date_iso8601_constraint.rb
173
161
  - lib/stronger_parameters/constraints/date_time_constraint.rb
174
162
  - lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb
175
163
  - lib/stronger_parameters/constraints/decimal_constraint.rb
@@ -183,6 +171,9 @@ files:
183
171
  - lib/stronger_parameters/constraints/nil_string_constraint.rb
184
172
  - lib/stronger_parameters/constraints/regexp_constraint.rb
185
173
  - lib/stronger_parameters/constraints/string_constraint.rb
174
+ - lib/stronger_parameters/constraints/time_constraint.rb
175
+ - lib/stronger_parameters/constraints/time_iso8601_constraint.rb
176
+ - lib/stronger_parameters/constraints/ulid_constraint.rb
186
177
  - lib/stronger_parameters/controller_support/permitted_parameters.rb
187
178
  - lib/stronger_parameters/errors.rb
188
179
  - lib/stronger_parameters/parameters.rb
@@ -207,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
198
  - !ruby/object:Gem::Version
208
199
  version: '0'
209
200
  requirements: []
210
- rubygems_version: 3.1.6
201
+ rubygems_version: 3.0.3.1
211
202
  signing_key:
212
203
  specification_version: 4
213
204
  summary: Type checking and type casting of parameters for Action Pack