Skip to content

Instantly share code, notes, and snippets.

@lobo-tuerto
Created December 4, 2008 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lobo-tuerto/32044 to your computer and use it in GitHub Desktop.
Save lobo-tuerto/32044 to your computer and use it in GitHub Desktop.
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