stronger_parameters 2.2.0 → 2.3.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: 86ccf1949f360c63a2bcd7f948d1755458ef421e
4
- data.tar.gz: 6831d7e4647b31e53ca425a6bf025b13b046d17e
3
+ metadata.gz: 4bb00ce9ad29124bfc1be428d0c6bb4b5f036406
4
+ data.tar.gz: d23f9e2b18039f83bbb601ba7bef6b6e44513fc2
5
5
  SHA512:
6
- metadata.gz: 6a9186f22c0e728addb01b0c7f6a531422953e0ee46e64e9f36c93b89606f191ad973b2e88bdfc62da0a0ce70189c42c5df4cb5ebd1647d8098f4c07541841d8
7
- data.tar.gz: ad27efca3d21ef6cc2ae267d4b77cc8ada855bb25bcd6aac3c961b48deee26e0169c1dc0e5e06da438461a041d66d66bc1da5c867c8914b2a864859e5b303261
6
+ metadata.gz: d659f024587214cdbb1350da3f8ed7841295c1f778af401e044b1ecb367f25f1361ac84c1086e5d58e3451043e3eeab5c44cb4544e1bc15b478808249660c609
7
+ data.tar.gz: 5667331c7df31f92cfda0b0ed87c57fc58076c282bc0191c4ef2e3b2814522a81558fc0e6474207a0ff1a5e6b7203df171648e0e58e0822a679a5133d839400b
data/README.md CHANGED
@@ -182,3 +182,4 @@ ActionController::Parameters.action_on_invalid_parameters = :log
182
182
  | Parameters.nil | value is nil |
183
183
  | Parameters.nil_string | value is nil, '', 'undefined' |
184
184
  | Parameters.file | File, StringIO, Rack::Test::UploadedFile, ActionDispatch::Http::UploadedFile or subclasses |
185
+ | Parameters.decimal(8,2) | value is a String, Integer or Float with a precision of 8 and scale of 2 |
@@ -0,0 +1,20 @@
1
+ require 'stronger_parameters/constraints'
2
+
3
+ module StrongerParameters
4
+ class DecimalConstraint < Constraint
5
+ def initialize(precision, scale)
6
+ @precision = precision
7
+ @scale = scale
8
+ @regex = /\A-?\d{1,#{precision - scale}}#{"(\\.\\d{1,#{scale}})?" if scale > 0}\Z/
9
+ end
10
+
11
+ def value(v)
12
+ match = v.to_s
13
+ if match =~ @regex
14
+ BigDecimal(match)
15
+ else
16
+ StrongerParameters::InvalidValue.new(v, "must be a decimal with precision #{@precision} and scale #{@scale}")
17
+ end
18
+ end
19
+ end
20
+ end
@@ -90,3 +90,4 @@ require 'stronger_parameters/constraints/enumeration_constraint'
90
90
  require 'stronger_parameters/constraints/comparison_constraints'
91
91
  require 'stronger_parameters/constraints/nil_string_constraint'
92
92
  require 'stronger_parameters/constraints/file_constraint'
93
+ require 'stronger_parameters/constraints/decimal_constraint'
@@ -113,6 +113,10 @@ module StrongerParameters
113
113
  def file
114
114
  FileConstraint.new
115
115
  end
116
+
117
+ def decimal(precision = 8, scale =2)
118
+ DecimalConstraint.new(precision, scale)
119
+ end
116
120
  end
117
121
 
118
122
  def hash_filter_with_stronger_parameters(params, filter)
@@ -1,3 +1,3 @@
1
1
  module StrongerParameters
2
- VERSION = '2.2.0'
2
+ VERSION = '2.3.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.2.0
4
+ version: 2.3.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-09-01 00:00:00.000000000 Z
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -178,6 +178,7 @@ files:
178
178
  - lib/stronger_parameters/constraints/boolean_constraint.rb
179
179
  - lib/stronger_parameters/constraints/comparison_constraints.rb
180
180
  - lib/stronger_parameters/constraints/date_time_constraint.rb
181
+ - lib/stronger_parameters/constraints/decimal_constraint.rb
181
182
  - lib/stronger_parameters/constraints/enumeration_constraint.rb
182
183
  - lib/stronger_parameters/constraints/file_constraint.rb
183
184
  - lib/stronger_parameters/constraints/float_constraint.rb