mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
properly chain multiparameter attributes
This commit is contained in:
parent
11e643c0fe
commit
4f0c81b6f8
@ -16,18 +16,16 @@ module ValidatesTimeliness
|
||||
def execute_callstack_for_multiparameter_attributes_with_timeliness(callstack)
|
||||
errors = []
|
||||
callstack.each do |name, values|
|
||||
klass = (self.class.reflect_on_aggregation(name.to_sym) || column_for_attribute(name)).klass
|
||||
if values.empty?
|
||||
send(name + "=", nil)
|
||||
else
|
||||
column = column_for_attribute(name)
|
||||
if column && [:date, :time, :datetime].include?(column.type)
|
||||
begin
|
||||
value = if [:date, :time, :datetime].include?(column.type)
|
||||
time_array_to_string(values, column.type)
|
||||
callstack.delete(name)
|
||||
if values.empty?
|
||||
send("#{name}=", nil)
|
||||
else
|
||||
klass.new(*values)
|
||||
value = time_array_to_string(values, column.type)
|
||||
send("#{name}=", value)
|
||||
end
|
||||
send(name + "=", value)
|
||||
rescue => ex
|
||||
errors << ::ActiveRecord::AttributeAssignmentError.new("error on assignment #{values.inspect} to #{name}", ex, name)
|
||||
end
|
||||
@ -36,10 +34,11 @@ module ValidatesTimeliness
|
||||
unless errors.empty?
|
||||
raise ::ActiveRecord::MultiparameterAssignmentErrors.new(errors), "#{errors.size} error(s) on assignment of multiparameter attributes"
|
||||
end
|
||||
execute_callstack_for_multiparameter_attributes_without_timeliness(callstack)
|
||||
end
|
||||
|
||||
def time_array_to_string(values, type)
|
||||
values = values.map(&:to_s)
|
||||
values = values.map {|v| v.to_s }
|
||||
|
||||
case type
|
||||
when :date
|
||||
|
||||
Loading…
Reference in New Issue
Block a user