Sha256: d752641dd6cba533e80c3709264c731319c35e270e5614ec7706d991c9cfe27e
Contents?: true
Size: 669 Bytes
Versions: 20
Compression:
Stored size: 669 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.') if time.utc? end end end end
Version data entries
20 entries across 20 versions & 1 rubygems