Module: Hanami::Validations::Predicates

Defined in:
lib/hanami/validations/predicates.rb

Overview

Mixin to include when defining shared predicates

Examples:

Inline Predicate

require 'hanami/validations'

module MySharedPredicates
  include Hanami::Validations::Predicates

  predicate :foo? do |actual|
    actual == 'foo'
  end
end

class MyValidator
  include Hanami::Validations
  predicates MySharedPredicates

  validations do
    required(:name).filled(:foo?)
  end
end

See Also:

Since:

  • 0.6.0

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.6.0



36
37
38
39
40
41
42
43
44
# File 'lib/hanami/validations/predicates.rb', line 36

def self.included(base)
  base.class_eval do
    include Dry::Logic::Predicates
    include Utils::ClassAttribute

    class_attribute :messages
    class_attribute :messages_path
  end
end