Module: Hanami::Validations::Predicates

Defined in:
lib/hanami/v1/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:

  • ClassMethods#predicates

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/v1/validations/predicates.rb', line 36

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

    class_attribute :messages
    class_attribute :messages_path
  end
end