Sha256: 1888177d64eda52c7953710ef93ee43be91ae49e09a50a6e5756acfbf56272c3

Contents?: true

Size: 1.02 KB

Versions: 14

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? do |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

14 entries across 14 versions & 1 rubygems

Version Path
hanami-validations-1.3.6 lib/hanami/validations/predicates.rb
hanami-validations-1.3.5 lib/hanami/validations/predicates.rb
hanami-validations-1.3.4 lib/hanami/validations/predicates.rb
hanami-validations-1.3.3 lib/hanami/validations/predicates.rb
hanami-validations-1.3.2 lib/hanami/validations/predicates.rb
hanami-validations-1.3.1 lib/hanami/validations/predicates.rb
hanami-validations-1.3.0 lib/hanami/validations/predicates.rb
hanami-validations-1.3.0.beta1 lib/hanami/validations/predicates.rb
hanami-validations-1.2.2 lib/hanami/validations/predicates.rb
hanami-validations-1.2.0 lib/hanami/validations/predicates.rb
hanami-validations-1.2.0.rc2 lib/hanami/validations/predicates.rb
hanami-validations-1.2.0.rc1 lib/hanami/validations/predicates.rb
hanami-validations-1.2.0.beta2 lib/hanami/validations/predicates.rb
hanami-validations-1.2.0.beta1 lib/hanami/validations/predicates.rb