measured-rails 0.0.8 → 0.0.9
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 +4 -4
- data/lib/measured/rails/active_record.rb +2 -2
- data/lib/measured/rails/validations.rb +3 -8
- data/lib/measured/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30cfdc7cf3a7bcdf8984107c7dec28b642646e10
|
4
|
+
data.tar.gz: 9eac87d730570d6b2e64ffb8c3bd4a8d707ec7c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b69f85fabb97c64ed67fe17472b4dea887def4e15ac5fbda554593d9aab128cdf7686876c2f676a08a915a9aa770c5118e38ee87faa038f4980baeb26c5ebc8a
|
7
|
+
data.tar.gz: 27b4dbb803cc1ab3ec9d055534367d2ed20a0e106dd76eed7eeb71a3d008fd295c75a0a8c9e828b9f58a537f05e335e67290ffd45bf4d2db90621c3055aca0ea
|
@@ -45,8 +45,8 @@ module Measured::Rails::ActiveRecord
|
|
45
45
|
precision = self.column_for_attribute(value_field_name).precision
|
46
46
|
scale = self.column_for_attribute(value_field_name).scale
|
47
47
|
rounded_to_scale_value = incoming.value.round(scale)
|
48
|
-
|
49
|
-
if rounded_to_scale_value.
|
48
|
+
|
49
|
+
if rounded_to_scale_value.to_i.to_s.length > (precision - scale)
|
50
50
|
raise Measured::Rails::Error, "The value #{rounded_to_scale_value} being set for column '#{value_field_name}' has too many significant digits. Please ensure it has no more than #{precision} significant digits."
|
51
51
|
end
|
52
52
|
public_send("#{ value_field_name }=", rounded_to_scale_value)
|
@@ -27,6 +27,7 @@ class MeasuredValidator < ActiveModel::EachValidator
|
|
27
27
|
|
28
28
|
options.slice(*CHECKS.keys).each do |option, value|
|
29
29
|
comparable_value = value_for(value, record)
|
30
|
+
comparable_value = measured_class.new(comparable_value, measurable_unit) if comparable_value.is_a?(Numeric)
|
30
31
|
unless measurable.public_send(CHECKS[option], comparable_value)
|
31
32
|
record.errors.add(attribute, message("#{measurable.to_s} must be #{CHECKS[option]} #{comparable_value}"))
|
32
33
|
end
|
@@ -48,14 +49,8 @@ class MeasuredValidator < ActiveModel::EachValidator
|
|
48
49
|
else
|
49
50
|
key
|
50
51
|
end
|
51
|
-
|
52
|
-
|
53
|
-
raise ArgumentError, ":#{ value } is a scalar. Please validate against a Measurable object with correct units" unless value == 0
|
54
|
-
return value
|
55
|
-
end
|
56
|
-
|
57
|
-
raise ArgumentError, ":#{ value } must be a Measurable object" unless value.is_a?(Measured::Measurable)
|
58
|
-
|
52
|
+
|
53
|
+
raise ArgumentError, ":#{ value } must be a number or a Measurable object" unless (value.is_a?(Numeric) || value.is_a?(Measured::Measurable))
|
59
54
|
value
|
60
55
|
end
|
61
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: measured-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin McPhillips
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|