Module: HasSafeDates::MultiparameterAttributeExt

Defined in:
lib/has_safe_dates/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#read_dateObject

Overrides #read_date when has_safe_dates is enabled for the current field the multiparameter. Otherwise the original #read_date method is invoked.



60
61
62
63
64
65
66
# File 'lib/has_safe_dates/core_ext.rb', line 60

def read_date
  if ActiveRecord::Base.has_safe_fields_config[object.class.base_class] && ActiveRecord::Base.has_safe_fields_config[object.class.base_class][:fields].include?(name)
    values.values_at(1,2,3).join("-")  # Convert multiparameter parts into a Date string, e.g. "2011-4-23", return it, and allow CoreExt methods handle the result.
  else
    super  # has_safe_dates is not enabled for the current field, so invoke the super method (original #read_date method).
  end
end

#read_timeObject

Overrides #read_time when has_safe_dates is enabled for the current field the multiparameter. Otherwise the original #read_date method is invoked.



70
71
72
73
74
75
76
# File 'lib/has_safe_dates/core_ext.rb', line 70

def read_time
  if ActiveRecord::Base.has_safe_fields_config[object.class.base_class] && ActiveRecord::Base.has_safe_fields_config[object.class.base_class][:fields].include?(name)
    "#{ values.values_at(1,2,3).join("-")} #{ values.values_at(4,5).join(":") }"  # Convert multiparameter parts into a Time string, e.g. "2011-4-23 12:34", return it, and allow CoreExt methods handle the result.
  else
    super  # has_safe_dates is not enabled for the current field, so invoke the super method (original #read_time method).
  end
end