Created
December 4, 2008 19:56
-
-
Save lobo-tuerto/32044 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validates_with_method :fecha_de_inicio, :method => :checa_es_dia_habil | |
def checa_es_dia_habil(campo) | |
if DiaInhabil.es_inhabil?(self.send(campo)) | |
return [false, "No es día hábil"] | |
end | |
true | |
end | |
validates_with_method :fecha_de_inicio, :method => :checa_es_dia_habil, :pass_field => true | |
class DataMapper::Validate::MethodValidator | |
def call(target) | |
result,message = if @options[:pass_field] | |
target.send(@options[:method], @field_name) | |
else | |
target.send(@options[:method]) | |
end | |
add_error(target,message,@field_name) if !result | |
result | |
end | |
end | |
class DataMapper::Validate::MethodValidator | |
def call(target) | |
#"#{@options[:method]} => #{target.method(@options[:method]).arity}".tap | |
result,message = if target.method(@options[:method]).arity > 0 | |
target.send(@options[:method], @field_name) | |
else | |
target.send(@options[:method]) | |
end | |
add_error(target,message,@field_name) if !result | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment