Sha256: 0f766a62c65c29655c7bd9366a72407077ffc559dc3146281a09c647b851787e

Contents?: true

Size: 771 Bytes

Versions: 1

Compression:

Stored size: 771 Bytes

Contents

module Dry
  class Matcher
    class Evaluator < BasicObject
      def initialize(result, cases)
        @cases = cases
        @result = result
        @matched = false
        @output = nil
      end

      def call
        yield self
        @output
      end

      def respond_to_missing?(name, include_private = false)
        @cases.key?(name) || super
      end

      def method_missing(name, *args, &block)
        return super unless @cases.key?(name)

        handle_case @cases[name], *args, &block
      end

      private

      def handle_case(kase, *pattern)
        return @output if @matched

        if kase.matches?(@result, *pattern)
          @matched = true
          @output = yield(kase.resolve(@result))
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-matcher-0.5.0 lib/dry/matcher/evaluator.rb