Sha256: 60730650b9b4eb7c721402c48fc5e61ce51894a760ba945df4adef55e1914029

Contents?: true

Size: 722 Bytes

Versions: 11

Compression:

Stored size: 722 Bytes

Contents

# frozen_string_literal: true

require 'dry/logic/rule_compiler'
require 'dry/logic/predicates'
require 'dry/logic/rule/predicate'

module Dry
  # Helper methods for constraint types
  #
  # @api public
  module Types
    # @param [Hash] options
    #
    # @return [Dry::Logic::Rule]
    #
    # @api public
    def self.Rule(options)
      rule_compiler.(
        options.map { |key, val|
          Logic::Rule::Predicate.build(
            Logic::Predicates[:"#{key}?"]
          ).curry(val).to_ast
        }
      ).reduce(:and)
    end

    # @return [Dry::Logic::RuleCompiler]
    #
    # @api private
    def self.rule_compiler
      @rule_compiler ||= Logic::RuleCompiler.new(Logic::Predicates)
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/dry-types-1.4.0/lib/dry/types/constraints.rb
dry-types-1.4.0 lib/dry/types/constraints.rb
dry-types-1.3.1 lib/dry/types/constraints.rb
dry-types-1.3.0 lib/dry/types/constraints.rb
dry-types-1.2.2 lib/dry/types/constraints.rb
dry-types-1.2.1 lib/dry/types/constraints.rb
dry-types-1.2.0 lib/dry/types/constraints.rb
dry-types-1.1.1 lib/dry/types/constraints.rb
dry-types-1.1.0 lib/dry/types/constraints.rb
dry-types-1.0.1 lib/dry/types/constraints.rb
dry-types-1.0.0 lib/dry/types/constraints.rb