measured-rails 0.0.8 → 0.0.9

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: 68355e20283509779816298a639059a8cbf389ee
4
- data.tar.gz: 93c43698257e4831d50da35d2525ced2cb1dae7b
3
+ metadata.gz: 30cfdc7cf3a7bcdf8984107c7dec28b642646e10
4
+ data.tar.gz: 9eac87d730570d6b2e64ffb8c3bd4a8d707ec7c2
5
5
  SHA512:
6
- metadata.gz: b0f42793e76e6cacae038d8843d91089163ae57501db98f939e3b0fe39012882412936b0a52def1c485f2f9fe4d3d1ba3b9b7e8322bc502a7ab1c4962dca5061
7
- data.tar.gz: fb820be61b40641dd5c16b40c243bc7a859b13d7dda91a4a95e1833fde9ea0077f306c124e4bd1e0265a4b4f94ae57d0c2d3aae0c155a0f8df2472ed6577172e
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
- ## For BigDecimal#split syntax, refer http://ruby-doc.org/stdlib-2.1.1/libdoc/bigdecimal/rdoc/BigDecimal.html#method-i-split
49
- if rounded_to_scale_value.split[1].size > precision
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
- if value.is_a?(Numeric)
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
@@ -1,5 +1,5 @@
1
1
  module Measured
2
2
  module Rails
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  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.8
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-06-29 00:00:00.000000000 Z
11
+ date: 2015-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails