stronger_parameters 2.2.0 → 2.3.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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bb00ce9ad29124bfc1be428d0c6bb4b5f036406
|
4
|
+
data.tar.gz: d23f9e2b18039f83bbb601ba7bef6b6e44513fc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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'
|
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.
|
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-
|
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
|