Sha256: fc73ad87d96dede5a9f3932658aea22d194d05a3d2376a2430a2ef7ebd3868f6

Contents?: true

Size: 532 Bytes

Versions: 20

Compression:

Stored size: 532 Bytes

Contents

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

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

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
dry-types-0.14.1 lib/dry/types/constraints.rb
dry-types-0.15.0 lib/dry/types/constraints.rb
dry-types-0.14.0 lib/dry/types/constraints.rb
dry-types-0.13.4 lib/dry/types/constraints.rb
dry-types-0.13.3 lib/dry/types/constraints.rb
dry-types-0.12.3 lib/dry/types/constraints.rb
dry-types-0.13.2 lib/dry/types/constraints.rb
dry-types-0.13.1 lib/dry/types/constraints.rb
dry-types-0.13.0 lib/dry/types/constraints.rb
dry-types-0.12.2 lib/dry/types/constraints.rb
dry-types-0.12.1 lib/dry/types/constraints.rb
dry-types-0.12.0 lib/dry/types/constraints.rb
dry-types-0.11.1 lib/dry/types/constraints.rb
dry-types-0.11.0 lib/dry/types/constraints.rb
dry-types-0.10.3 lib/dry/types/constraints.rb
dry-types-0.10.2 lib/dry/types/constraints.rb
dry-types-0.10.1 lib/dry/types/constraints.rb
dry-types-0.10.0 lib/dry/types/constraints.rb
dry-types-0.9.4 lib/dry/types/constraints.rb
dry-types-0.9.3 lib/dry/types/constraints.rb