Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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