Module: ValidatesTimeliness::ActiveRecord::AttributeMethods::ClassMethods

Defined in:
lib/validates_timeliness/active_record/attribute_methods.rb

Instance Method Summary collapse

Instance Method Details

#define_attribute_methods_with_timelinessObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/validates_timeliness/active_record/attribute_methods.rb', line 46

def define_attribute_methods_with_timeliness
  return if generated_methods?
  timeliness_methods = []

  columns_hash.each do |name, column|
    if [:date, :time, :datetime].include?(column.type)
      time_zone_aware = create_time_zone_conversion_attribute?(name, column) rescue false

      define_method("#{name}=") do |value|
        write_date_time_attribute(name, value, column.type, time_zone_aware)
      end
      timeliness_methods << name
    end
  end

  define_attribute_methods_without_timeliness
  @generated_methods += timeliness_methods
end