class Dry::Logic::Operations::Key

Attributes

evaluator[R]
path[R]

Public Class Methods

evaluator(name) click to toggle source
# File lib/dry/logic/operations/key.rb, line 21
def self.evaluator(name)
  Evaluator::Key.new(name)
end
new(rules, **options) click to toggle source
Calls superclass method
# File lib/dry/logic/operations/key.rb, line 11
def self.new(rules, **options)
  if options[:evaluator]
    super
  else
    name = options.fetch(:name)
    eval = options.fetch(:evaluator, evaluator(name))
    super(rules, **options, evaluator: eval, path: name)
  end
end
new(*rules, **options) click to toggle source
Calls superclass method
# File lib/dry/logic/operations/key.rb, line 25
def initialize(*rules, **options)
  super
  @evaluator = options[:evaluator]
  @path = options[:path]
end

Public Instance Methods

[](hash) click to toggle source
# File lib/dry/logic/operations/key.rb, line 46
def [](hash)
  rule[evaluator[hash]]
end
ast(input = Undefined) click to toggle source
# File lib/dry/logic/operations/key.rb, line 50
def ast(input = Undefined)
  if input.equal?(Undefined) || !input.is_a?(Hash)
    [type, [path, rule.ast]]
  else
    [type, [path, rule.ast(evaluator[input])]]
  end
end
call(hash) click to toggle source
# File lib/dry/logic/operations/key.rb, line 35
def call(hash)
  input = evaluator[hash]
  result = rule.(input)

  if result.success?
    Result::SUCCESS
  else
    Result.new(false, path) { [type, [path, result.to_ast]] }
  end
end
to_s() click to toggle source
# File lib/dry/logic/operations/key.rb, line 58
def to_s
  "#{type}[#{path}](#{rule})"
end
type() click to toggle source
# File lib/dry/logic/operations/key.rb, line 31
def type
  :key
end