Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with own predicates #15

Closed
wafcio opened this issue Nov 28, 2015 · 2 comments
Closed

Problem with own predicates #15

wafcio opened this issue Nov 28, 2015 · 2 comments

Comments

@wafcio
Copy link

wafcio commented Nov 28, 2015

Based on example in README

module MyPredicates
  include Dry::Validation::Predicates

  predicate(:uuid?) do |input|
    ! /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/.match(input).nil?
  end
end

class Schema < Dry::Validation::Schema
  configure do |config|
    config.predicates = MyPredicates
  end

  key(:id) { |value| value.str? & value.uuid? }
end

When I am writing:

Schema.new.messages({ id: "aaa" })

I always receive:

NoMethodError: undefined method `visit_uuid?' for #<Dry::Validation::ErrorCompiler:0x007f83c40c31f0>
@solnic solnic closed this as completed in 185ec9d Nov 29, 2015
@wafcio
Copy link
Author

wafcio commented Nov 29, 2015

In my errors.yml, I added uuid? key so I have message, but what about visit_uuid?

uuid?: "invalid"

@solnic solnic reopened this Nov 29, 2015
@solnic
Copy link
Member

solnic commented Nov 29, 2015

Oh of course, sorry about that. I need to clean-up error message compiler and provide a fall-back visitor for generic predicate messages. Will do it today.

@solnic solnic closed this as completed in 3a4d220 Nov 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants