Module: ValidatesTimeliness::ActiveRecord::MultiparameterAttributes
- Defined in:
- lib/validates_timeliness/active_record/multiparameter_attributes.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#execute_callstack_for_multiparameter_attributes_with_timeliness(callstack) ⇒ Object
Assign dates and times as formatted strings to force the use of the plugin parser.
Class Method Details
.included(base) ⇒ Object
37 38 39 |
# File 'lib/validates_timeliness/active_record/multiparameter_attributes.rb', line 37 def self.included(base) base.alias_method_chain :execute_callstack_for_multiparameter_attributes, :timeliness end |
Instance Method Details
#execute_callstack_for_multiparameter_attributes_with_timeliness(callstack) ⇒ Object
Assign dates and times as formatted strings to force the use of the plugin parser
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/validates_timeliness/active_record/multiparameter_attributes.rb', line 42 def execute_callstack_for_multiparameter_attributes_with_timeliness(callstack) errors = [] callstack.each do |name, values| column = column_for_attribute(name) if column && [:date, :time, :datetime].include?(column.type) begin callstack.delete(name) if values.empty? || values.all?(&:nil?) send("#{name}=", nil) else value = ValidatesTimeliness::ActiveRecord.time_array_to_string(values, column.type) send("#{name}=", value) end rescue => ex errors << ::ActiveRecord::AttributeAssignmentError.new("error on assignment #{values.inspect} to #{name}", ex, name) end end end 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 |