Sha256: 36e9e0b9a6d4a5e9fdaf2e881e8135281c96613db22f82b7a4e237c6e27cc9ca
Contents?: true
Size: 689 Bytes
Versions: 35
Compression:
Stored size: 689 Bytes
Contents
# frozen_string_literal: true # https://guides.rubyonrails.org/active_record_validations.html#validates-with module Dsu module Validators class TimeValidator < ActiveModel::Validator def validate(record) time = record.time if time.nil? record.errors.add(:time, :blank) return end unless time.is_a?(Time) record.errors.add(:time, 'is the wrong object type. ' \ "\"Time\" was expected, but \"#{time.class}\" was received.") return end record.errors.add(:time, 'is not in localtime format.') unless time == time.in_time_zone end end end end
Version data entries
35 entries across 35 versions & 1 rubygems