mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 06:16:44 +00:00
move validation helpers into ActiveModel::Validations for default base support add check if attribute methods shim is being used refactor specs for helper and attribute methods separation more mongoid workarounds due to incorrect use of AS::Concern
29 lines
817 B
Ruby
29 lines
817 B
Ruby
module ActiveModel
|
|
module Validations
|
|
|
|
module HelperMethods
|
|
def validates_date(*attr_names)
|
|
timeliness_validation_for attr_names, :date
|
|
end
|
|
|
|
def validates_time(*attr_names)
|
|
timeliness_validation_for attr_names, :time
|
|
end
|
|
|
|
def validates_datetime(*attr_names)
|
|
timeliness_validation_for attr_names, :datetime
|
|
end
|
|
|
|
def timeliness_validation_for(attr_names, type)
|
|
options = _merge_attributes(attr_names).merge(:type => type)
|
|
if respond_to?(:timeliness_validated_attributes)
|
|
self.timeliness_validated_attributes ||= []
|
|
self.timeliness_validated_attributes += (attr_names - self.timeliness_validated_attributes)
|
|
end
|
|
validates_with ValidatesTimeliness::Validator, options
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|