Sha256: 73cb000d3c6a8648c3dd9351c812656a510f146204189649ffddc3acb0ab3bf6

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

module ValidatesTimeliness
  module ORM
    module ActiveRecord
      extend ActiveSupport::Concern

      module ClassMethods
        def define_attribute_methods
          super
          # Define write method and before_type_cast method
          use_before_type_cast = ::ActiveRecord::VERSION::STRING < '3.1.0'
          define_timeliness_methods(use_before_type_cast)
        end

        def timeliness_attribute_timezone_aware?(attr_name)
          attr_name = attr_name.to_s
          create_time_zone_conversion_attribute?(attr_name, columns_hash[attr_name])
        end

        def timeliness_attribute_type(attr_name)
          columns_hash[attr_name.to_s].type
        end

        def timeliness_type_cast_code(attr_name, var_name)
          type = timeliness_attribute_type(attr_name)

          <<-END
            #{super}
            #{var_name} = #{var_name}.to_date if #{var_name} && :#{type} == :date
          END
        end
      end

      def reload(*args)
        _clear_timeliness_cache
        super
      end
    end
  end
end

class ActiveRecord::Base
  include ValidatesTimeliness::AttributeMethods
  include ValidatesTimeliness::ORM::ActiveRecord
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
validates_timeliness-3.0.8 lib/validates_timeliness/orm/active_record.rb