Sha256: 89deb834634c2dad2d285121806275124714306dd43a8dbbb4abe7e67395e991

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 KB

Contents

require 'dry/logic/predicates'
require 'hanami/utils/class_attribute'

module Hanami
  module Validations
    # Mixin to include when defining shared predicates
    #
    # @since 0.6.0
    #
    # @see Hanami::Validations::ClassMethods#predicates
    #
    # @example Inline Predicate
    #   require 'hanami/validations'
    #
    #   module MySharedPredicates
    #     include Hanami::Validations::Predicates
    #
    #     predicate :foo? fo |actual|
    #       actual == 'foo'
    #     end
    #   end
    #
    #   class MyValidator
    #     include Hanami::Validations
    #     predicates MySharedPredicates
    #
    #     validations do
    #       required(:name).filled(:foo?)
    #     end
    #   end
    module Predicates
      # @since 0.6.0
      # @api private
      def self.included(base)
        base.class_eval do
          include Dry::Logic::Predicates
          include Utils::ClassAttribute

          class_attribute :messages
          class_attribute :messages_path
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hanami-validations-1.1.0 lib/hanami/validations/predicates.rb
hanami-validations-1.1.0.rc1 lib/hanami/validations/predicates.rb
hanami-validations-1.1.0.beta3 lib/hanami/validations/predicates.rb
hanami-validations-1.1.0.beta2 lib/hanami/validations/predicates.rb
hanami-validations-1.1.0.beta1 lib/hanami/validations/predicates.rb
hanami-validations-1.0.0 lib/hanami/validations/predicates.rb
hanami-validations-1.0.0.rc1 lib/hanami/validations/predicates.rb
hanami-validations-1.0.0.beta2 lib/hanami/validations/predicates.rb