stronger_parameters 2.17.0 → 2.19.1

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: 6b498cb065e3370fff5def0735395b8b396565f62e76364612f7ab101ecc3c63
4
+ data.tar.gz: 7edd672e06906c24efc86aff49783659df49e390918693dcf1c2dab174dfb8b2
5
5
  SHA512:
6
- metadata.gz: bc0642f85f672bf56faf7e139e1ea895206a6985f7b8b7a4c5034e1bd023696af0796307fa478007c462c39f2d3dc47fdc769269990e4b0c5be51691709e0d54
7
- data.tar.gz: 133a07b885c0a2d7612e5a8b46c9c53b05534a9be921738a571f910ea6de9c166bebb1891640537e707aa5c6b96fec234cddccde2a860b03d6e0cbff9d5da3d6
6
+ metadata.gz: 1d17d12e4b23862fd3dd7d6663a660d26324f29c392e7af6577c4792d0df53c01c20f45a8a99c6b8a57870c43650a580d9f57796528624450e8b59e7482d4cb1
7
+ data.tar.gz: aa06279656cb6ebc52e133e1f7a0d61fe439b0bf88b9e6e6521898cec61986c6799f1b0ce63d70f0a1edb7f3eb7005fc19103606df44fc6f765c17e73bb3bdd9
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
+
275
+ ## Development
276
+
277
+ ### Releasing a new version
278
+
279
+ ```
280
+ git checkout master && git fetch origin && git reset --hard origin/master
281
+ bundle exec rake bump:<patch|minor|major>
282
+ git tag v<tag>
283
+ git push --tags
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
@@ -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'
@@ -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
@@ -160,7 +176,7 @@ module StrongerParameters
160
176
 
161
177
  if result.is_a?(InvalidValue)
162
178
  name = "invalid_parameter.action_controller"
163
- ActiveSupport::Notifications.publish(name, key: key, value: value, message: result.message)
179
+ ActiveSupport::Notifications.instrument(name, key: key, value: value, message: result.message)
164
180
 
165
181
  action = self.class.action_on_invalid_parameters
166
182
  case action
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module StrongerParameters
3
- VERSION = '2.17.0'
3
+ VERSION = '2.19.1'
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.19.1
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: 2022-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -170,6 +170,8 @@ files:
170
170
  - lib/stronger_parameters/constraints/array_constraint.rb
171
171
  - lib/stronger_parameters/constraints/boolean_constraint.rb
172
172
  - lib/stronger_parameters/constraints/comparison_constraints.rb
173
+ - lib/stronger_parameters/constraints/date_constraint.rb
174
+ - lib/stronger_parameters/constraints/date_iso8601_constraint.rb
173
175
  - lib/stronger_parameters/constraints/date_time_constraint.rb
174
176
  - lib/stronger_parameters/constraints/date_time_iso8601_constraint.rb
175
177
  - lib/stronger_parameters/constraints/decimal_constraint.rb
@@ -183,6 +185,8 @@ files:
183
185
  - lib/stronger_parameters/constraints/nil_string_constraint.rb
184
186
  - lib/stronger_parameters/constraints/regexp_constraint.rb
185
187
  - lib/stronger_parameters/constraints/string_constraint.rb
188
+ - lib/stronger_parameters/constraints/time_constraint.rb
189
+ - lib/stronger_parameters/constraints/time_iso8601_constraint.rb
186
190
  - lib/stronger_parameters/controller_support/permitted_parameters.rb
187
191
  - lib/stronger_parameters/errors.rb
188
192
  - lib/stronger_parameters/parameters.rb
@@ -207,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
211
  - !ruby/object:Gem::Version
208
212
  version: '0'
209
213
  requirements: []
210
- rubygems_version: 3.1.6
214
+ rubygems_version: 3.0.3.1
211
215
  signing_key:
212
216
  specification_version: 4
213
217
  summary: Type checking and type casting of parameters for Action Pack