4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/money-rails/active_model/validator.rb', line 4
def validate_each(record, attr, value)
reset_memoized_variables!
@record = record
@attr = attr
subunit_attr = @record.class.monetized_attributes[@attr.to_sym]
before_type_cast = :"#{@attr}_money_before_type_cast"
@raw_value = @record.try(before_type_cast)
if @raw_value.nil? && @record.public_send(subunit_attr)
subunit_value = @record.public_send(subunit_attr)
@raw_value = subunit_value.to_f / currency.subunit_to_unit
end
return if options[:allow_nil] && @raw_value.nil?
if raw_value_is_non_numeric
@raw_value = @raw_value.to_s.strip.gsub(symbol, "")
add_error and return if value_has_too_many_decimal_points
add_error if invalid_thousands_separation
end
normalize_raw_value!
super(@record, @attr, @raw_value)
end
|