class Dry::Logic::Operations::Check

Attributes

evaluator[R]

Public Class Methods

new(rule, **options) click to toggle source
Calls superclass method
# File lib/dry/logic/operations/check.rb, line 13
def self.new(rule, **options)
  if options[:evaluator]
    super(rule, **options)
  else
    keys = options.fetch(:keys)
    evaluator = Evaluator::Set.new(keys)

    super(rule, **options, evaluator: evaluator)
  end
end
new(*rules, **options) click to toggle source
Calls superclass method
# File lib/dry/logic/operations/check.rb, line 24
def initialize(*rules, **options)
  super
  @evaluator = options[:evaluator]
end

Public Instance Methods

[](input) click to toggle source
# File lib/dry/logic/operations/check.rb, line 44
def [](input)
  rule[*evaluator[input].reverse]
end
ast(input = Undefined) click to toggle source
# File lib/dry/logic/operations/check.rb, line 48
def ast(input = Undefined)
  [type, [options[:keys], rule.ast(input)]]
end
call(input) click to toggle source
# File lib/dry/logic/operations/check.rb, line 33
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
type() click to toggle source
# File lib/dry/logic/operations/check.rb, line 29
def type
  :check
end