Sha256: a5dc73715ed315794ee555bdf266f8114abe2d6b131df27c45aa9406da3bc4dc
Contents?: true
Size: 982 Bytes
Versions: 5
Compression:
Stored size: 982 Bytes
Contents
# frozen_string_literal: true require 'dry/equalizer' module Dry module Logic class Evaluator include Dry::Equalizer(:path) attr_reader :path class Set include Dry::Equalizer(:evaluators) attr_reader :evaluators def self.new(paths) super(paths.map { |path| Evaluator::Key.new(path) }) end def initialize(evaluators) @evaluators = evaluators end def call(input) evaluators.map { |evaluator| evaluator[input] } end alias_method :[], :call end class Key < Evaluator def call(input) path.reduce(input) { |a, e| a[e] } end alias_method :[], :call end class Attr < Evaluator def call(input) path.reduce(input) { |a, e| a.public_send(e) } end alias_method :[], :call end def initialize(path) @path = Array(path) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems