mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
clean up valdiation methods
This commit is contained in:
parent
27e01486e9
commit
f0e9d0292a
@ -10,32 +10,30 @@ module ValidatesTimeliness
|
|||||||
end
|
end
|
||||||
|
|
||||||
module ValidationMethods
|
module ValidationMethods
|
||||||
def validates_timeliness_of(*attr_names)
|
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)
|
options = _merge_attributes(attr_names)
|
||||||
attributes = options[:attributes].inject({}) {|validated, attr_name|
|
options[:type] = type
|
||||||
|
attributes = attr_names.inject({}) {|validated, attr_name|
|
||||||
attr_name = attr_name.to_s
|
attr_name = attr_name.to_s
|
||||||
validated[attr_name] = options[:type]
|
validated[attr_name] = type
|
||||||
validated
|
validated
|
||||||
}
|
}
|
||||||
self.timeliness_validated_attributes = attributes
|
self.timeliness_validated_attributes = attributes
|
||||||
validates_with Validator, options
|
validates_with Validator, options
|
||||||
end
|
end
|
||||||
|
|
||||||
def validates_date(*attr_names)
|
|
||||||
options = attr_names.extract_options!
|
|
||||||
validates_timeliness_of *(attr_names << options.merge(:type => :date))
|
|
||||||
end
|
|
||||||
|
|
||||||
def validates_time(*attr_names)
|
|
||||||
options = attr_names.extract_options!
|
|
||||||
validates_timeliness_of *(attr_names << options.merge(:type => :time))
|
|
||||||
end
|
|
||||||
|
|
||||||
def validates_datetime(*attr_names)
|
|
||||||
options = attr_names.extract_options!
|
|
||||||
validates_timeliness_of *(attr_names << options.merge(:type => :datetime))
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user