Sha256: 7779bd1e3fce288361febe22a494a984e860a0ad5016e6c8911765f8828111b1
Contents?: true
Size: 1.04 KB
Versions: 1
Compression:
Stored size: 1.04 KB
Contents
# frozen_string_literal: true module Dry module Logic module Operations class Check < Unary attr_reader :evaluator def self.new(rule, **options) if options[:evaluator] super else keys = options.fetch(:keys) evaluator = Evaluator::Set.new(keys) super(rule, **options, evaluator: evaluator) end end def initialize(*rules, **options) super @evaluator = options[:evaluator] end def type :check end def call(input) *head, tail = evaluator[input] result = rule.curry(*head).(tail) if result.success? Result::SUCCESS else Result.new(false, id) { [type, [options[:keys], result.to_ast]] } end end def [](input) rule[*evaluator[input].reverse] end def ast(input = Undefined) [type, [options[:keys], rule.ast(input)]] end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dry-logic-1.6.0 | lib/dry/logic/operations/check.rb |