Module: ValidatesTimeliness::ORM::ActiveRecord

Extended by:
ActiveSupport::Concern
Included in:
ActiveRecord::Base
Defined in:
lib/validates_timeliness/orm/active_record.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#read_timeliness_attribute_before_type_cast(attr_name) ⇒ Object



83
84
85
# File 'lib/validates_timeliness/orm/active_record.rb', line 83

def read_timeliness_attribute_before_type_cast(attr_name)
  @timeliness_cache && @timeliness_cache[attr_name] || read_attribute_before_type_cast(attr_name)
end

#reload(*args) ⇒ Object



87
88
89
90
# File 'lib/validates_timeliness/orm/active_record.rb', line 87

def reload(*args)
  _clear_timeliness_cache
  super
end

#write_timeliness_attribute(attr_name, value) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/validates_timeliness/orm/active_record.rb', line 69

def write_timeliness_attribute(attr_name, value)
  @timeliness_cache ||= {}
  @timeliness_cache[attr_name] = value

  if ValidatesTimeliness.use_plugin_parser
    type = self.class.timeliness_attribute_type(attr_name)
    timezone = :current if self.class.timeliness_attribute_timezone_aware?(attr_name)
    value = Timeliness::Parser.parse(value, type, :zone => timezone)
    value = value.to_date if value && type == :date
  end

  write_attribute(attr_name, value)
end