stronger_parameters 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82c729731aba352921088c9f5663959a1c131e75
4
- data.tar.gz: 8420c1edf43f748f386932e65981897b56bb9d54
3
+ metadata.gz: 86ccf1949f360c63a2bcd7f948d1755458ef421e
4
+ data.tar.gz: 6831d7e4647b31e53ca425a6bf025b13b046d17e
5
5
  SHA512:
6
- metadata.gz: c2ef5a4633fd37911e179d0705471f58693e9960275cfe30110ace7201961c4fc993cb2d2258b519d72816834cd3a7cf9f41ac7cd968f6b8285f00f20619419c
7
- data.tar.gz: d8bedec8097ccaee8de5ee1ac6477dc88d3c6699b166b0517dc2b9317659770a8f171b61a75e3372a002a74540daf9b7df3222f9ee8e0280bec449b658051a7c
6
+ metadata.gz: 6a9186f22c0e728addb01b0c7f6a531422953e0ee46e64e9f36c93b89606f191ad973b2e88bdfc62da0a0ce70189c42c5df4cb5ebd1647d8098f4c07541841d8
7
+ data.tar.gz: ad27efca3d21ef6cc2ae267d4b77cc8ada855bb25bcd6aac3c961b48deee26e0169c1dc0e5e06da438461a041d66d66bc1da5c867c8914b2a864859e5b303261
data/README.md CHANGED
@@ -160,24 +160,25 @@ ActionController::Parameters.action_on_invalid_parameters = :log
160
160
 
161
161
  ## Types
162
162
 
163
- | Syntax | (Simplified) Definition |
164
- |--------------------------------|-------------------------------------------------------------------------|
165
- | Parameters.string | value.is_a?(String) |
166
- | Parameters.integer | value.is_a?(Fixnum) or '-1' |
167
- | Parameters.float | value.is_a?(Float) or '-1.2' |
168
- | Parameters.datetime | value.is_a?(DateTime) or '2014-05-13' or '2015-03-31T14:34:56Z' |
169
- | Parameters.regexp(/foo/) | value =~ regexp |
170
- | Parameters.enum('asc', 'desc') | ['asc', 'desc'].include?(value) |
171
- | Parameters.lt(10) | value < 10 |
172
- | Parameters.lte(10) | value <= 10 |
173
- | Parameters.gt(0) | value > 0 |
174
- | Parameters.gte(0) | value >= 0 |
175
- | Parameters.integer32 | Parameters.integer & Parameters.lt(2 ** 31) & Parameters.gte(-2 ** 31) |
176
- | Parameters.integer64 | Parameters.integer & Parameters.lt(2 ** 63) & Parameters.gte(-2 ** 63) |
177
- | Parameters.id | Parameters.integer & Parameters.lt(2 ** 31) & Parameters.gte(0) |
178
- | Parameters.bigid | Parameters.integer & Parameters.lt(2 ** 63) & Parameters.gte(0) |
179
- | Parameters.uid | Parameters.integer & Parameters.lt(2 ** 32) & Parameters.gte(0) |
180
- | Parameters.ubigid | Parameters.integer & Parameters.lt(2 ** 64) & Parameters.gte(0) |
181
- | Parameters.boolean | Parameters.enum(true, false, 'true', 'false', 1, 0) |
182
- | Parameters.nil | value is nil |
183
- | Parameters.nil_string | value is nil, '', 'undefined' |
163
+ | Syntax | (Simplified) Definition |
164
+ |--------------------------------|--------------------------------------------------------------------------------------------|
165
+ | Parameters.string | value.is_a?(String) |
166
+ | Parameters.integer | value.is_a?(Fixnum) or '-1' |
167
+ | Parameters.float | value.is_a?(Float) or '-1.2' |
168
+ | Parameters.datetime | value.is_a?(DateTime) or '2014-05-13' or '2015-03-31T14:34:56Z' |
169
+ | Parameters.regexp(/foo/) | value =~ regexp |
170
+ | Parameters.enum('asc', 'desc') | ['asc', 'desc'].include?(value) |
171
+ | Parameters.lt(10) | value < 10 |
172
+ | Parameters.lte(10) | value <= 10 |
173
+ | Parameters.gt(0) | value > 0 |
174
+ | Parameters.gte(0) | value >= 0 |
175
+ | Parameters.integer32 | Parameters.integer & Parameters.lt(2 ** 31) & Parameters.gte(-2 ** 31) |
176
+ | Parameters.integer64 | Parameters.integer & Parameters.lt(2 ** 63) & Parameters.gte(-2 ** 63) |
177
+ | Parameters.id | Parameters.integer & Parameters.lt(2 ** 31) & Parameters.gte(0) |
178
+ | Parameters.bigid | Parameters.integer & Parameters.lt(2 ** 63) & Parameters.gte(0) |
179
+ | Parameters.uid | Parameters.integer & Parameters.lt(2 ** 32) & Parameters.gte(0) |
180
+ | Parameters.ubigid | Parameters.integer & Parameters.lt(2 ** 64) & Parameters.gte(0) |
181
+ | Parameters.boolean | Parameters.enum(true, false, 'true', 'false', 1, 0) |
182
+ | Parameters.nil | value is nil |
183
+ | Parameters.nil_string | value is nil, '', 'undefined' |
184
+ | Parameters.file | File, StringIO, Rack::Test::UploadedFile, ActionDispatch::Http::UploadedFile or subclasses |
@@ -0,0 +1,20 @@
1
+ require 'stronger_parameters/constraints'
2
+
3
+ module StrongerParameters
4
+ class FileConstraint < Constraint
5
+ VALID_FILE_TYPES = [
6
+ File,
7
+ StringIO,
8
+ Rack::Test::UploadedFile,
9
+ ActionDispatch::Http::UploadedFile
10
+ ]
11
+
12
+ def value(v)
13
+ if VALID_FILE_TYPES.any? { |valid_file_type| v.is_a?(valid_file_type) }
14
+ return v
15
+ end
16
+
17
+ InvalidValue.new(v, "must be an file object")
18
+ end
19
+ end
20
+ end
@@ -89,3 +89,4 @@ require 'stronger_parameters/constraints/hash_constraint'
89
89
  require 'stronger_parameters/constraints/enumeration_constraint'
90
90
  require 'stronger_parameters/constraints/comparison_constraints'
91
91
  require 'stronger_parameters/constraints/nil_string_constraint'
92
+ require 'stronger_parameters/constraints/file_constraint'
@@ -109,6 +109,10 @@ module StrongerParameters
109
109
  def datetime
110
110
  DateTimeConstraint.new
111
111
  end
112
+
113
+ def file
114
+ FileConstraint.new
115
+ end
112
116
  end
113
117
 
114
118
  def hash_filter_with_stronger_parameters(params, filter)
@@ -1,3 +1,3 @@
1
1
  module StrongerParameters
2
- VERSION = '2.1.2'
2
+ VERSION = '2.2.0'
3
3
  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.1.2
4
+ version: 2.2.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: 2015-08-31 00:00:00.000000000 Z
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -179,6 +179,7 @@ files:
179
179
  - lib/stronger_parameters/constraints/comparison_constraints.rb
180
180
  - lib/stronger_parameters/constraints/date_time_constraint.rb
181
181
  - lib/stronger_parameters/constraints/enumeration_constraint.rb
182
+ - lib/stronger_parameters/constraints/file_constraint.rb
182
183
  - lib/stronger_parameters/constraints/float_constraint.rb
183
184
  - lib/stronger_parameters/constraints/hash_constraint.rb
184
185
  - lib/stronger_parameters/constraints/integer_constraint.rb