Closed tiagoengel closed 8 years ago
clean and beautiful. go ahead :+1:
more one point, remember create test to this feature .
@tiagoengel What do you thing, change validate_cnpj and validate_cpf to validate_cpfcnpj and using (:cnpj, :cpf) to select the correct validation ?
Maybe internally we could do that, but I prefer the API with the two functions, 'cause a function call like this would be a little bit confusing.
validate_cpfcnpf(:cnpj, :cnpj)
ok no problem. i close the issue.
:+1:
2 functions is good, i don't understend why using atom
validate_cnpj(:cnpj, message: "Cnpj inválido')
validate_cpf(:cpf, message: "Cpf inválido')
instead
validate_cnpj(message: "Cnpj inválido')
validate_cpf(message: "Cpf inválido')
is a Ecto limitation ?
:cnpj/:cpf in this case are field names. For instance, if I have a model definition like this:
defmodule Company do
schema "companies" do
field :name, :string
field :numero_cnpj, :string
end
end
I would have to call the function this way:
validate_cnpj(:numero_cnpj, message: "Cnpj inválido')
:heart: :green_heart: :blue_heart:
I was thinking on adding some methods to add support for the Ecto changeset api. Would look something like this:
What do you think?