mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
Rails 4.0 and 4.1 compat for #setup method removal
This commit is contained in:
parent
4d48c3578b
commit
bb830baea2
@ -14,8 +14,16 @@ module ActiveModel
|
||||
timeliness_validation_for attr_names, :datetime
|
||||
end
|
||||
|
||||
def timeliness_validation_for(attr_names, type)
|
||||
validates_with TimelinessValidator, _merge_attributes(attr_names).merge(:type => type)
|
||||
def validates_timeliness_of(*attr_names)
|
||||
timeliness_validation_for attr_names
|
||||
end
|
||||
|
||||
def timeliness_validation_for(attr_names, type=nil)
|
||||
options = _merge_attributes(attr_names)
|
||||
options.update(:type => type) if type
|
||||
# Rails 4.0 and 4.1 compatibility for old #setup method with class as arg
|
||||
options.update(:class => self) unless options.has_key?(:class)
|
||||
validates_with TimelinessValidator, _merge_attributes(attr_names)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ module ValidatesTimeliness
|
||||
class Validator < ActiveModel::EachValidator
|
||||
include Conversion
|
||||
|
||||
attr_reader :type
|
||||
attr_reader :type, :attributes
|
||||
|
||||
RESTRICTIONS = {
|
||||
:is_at => :==,
|
||||
@ -42,13 +42,14 @@ module ValidatesTimeliness
|
||||
end
|
||||
|
||||
@restrictions_to_check = RESTRICTIONS.keys & options.keys
|
||||
super
|
||||
end
|
||||
|
||||
def setup(model)
|
||||
super
|
||||
|
||||
model = options[:class]
|
||||
|
||||
if model.respond_to?(:timeliness_validated_attributes)
|
||||
model.timeliness_validated_attributes ||= []
|
||||
model.timeliness_validated_attributes |= @attributes
|
||||
model.timeliness_validated_attributes |= attributes
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user