Sha256: 8addf0adb544c5ddcde5f7d574b5a97b1534c12d88e86d302cd9a27b17fdf382
Contents?: true
Size: 951 Bytes
Versions: 7
Compression:
Stored size: 951 Bytes
Contents
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
7 entries across 7 versions & 1 rubygems