I'd like to define a custom validator named :uk_date for use rather
like the exsiting :email and :url formats.
I've modified a copy of the url.rb file from the dm-validations format
folder to define my own (code below)
But where does it need to go to be included in the project?
I put it in my lib folder but at run time I get "No such predefined
format 'uk_date'"
(Am using merb and I have "Merb.push_path(:lib, Merb.root / 'lib', '**/
*.rb')" in my init.rb)
Is this the right approach to define another :format?
Many thanks,
George
module DataMapper
module Validate
module Format
module UkDate
def self.included(base)
DataMapper::Validate::FormatValidator::FORMATS.merge!(
:uk_date => [ UkDate, lambda { |field, value| '%s is not a
valid UK date'.t(value) }]
)
end
UkDate = begin
/^[0-3]?[0-9][\-\/][0-1]?[0-9][\-\/][0-9][0-9][0-9][0-9]$/i
end
end # module UkDate
end # module Format
end # module Validate
end # module DataMapper
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.