Sha256: ade1a59a95b56029060e31f3866bc94166daffe31ec6c0b731cb51a57b1aa1ac

Contents?: true

Size: 1.43 KB

Versions: 8

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module Mutant
  class Matcher

    # Compiler for complex matchers
    class Compiler
      include Concord.new(:config), AST::Sexp, Procto.call(:result)

      # Generated matcher
      #
      # @return [Matcher]
      def result
        Filter.new(
          Chain.new(config.match_expressions.map(&:matcher)),
          Morpher::Evaluator::Predicate::Boolean::And.new(
            [
              ignored_subjects,
              filtered_subjects
            ]
          )
        )
      end

      # Subject expression prefix predicate
      class SubjectPrefix
        include Concord.new(:expression)

        # Test if subject expression is matched by prefix
        #
        # @return [Boolean]
        def call(subject)
          expression.prefix?(subject.expression)
        end

      end # SubjectPrefix

    private

      # Predicate returning false on expression ignored subject
      #
      # @return [#call]
      def ignored_subjects
        Morpher::Evaluator::Predicate::Boolean::Negation.new(
          Morpher::Evaluator::Predicate::Boolean::Or.new(
            config.ignore_expressions.map(&SubjectPrefix.method(:new))
          )
        )
      end

      # Predicate returning false on filtered subject
      #
      # @return [#call]
      def filtered_subjects
        Morpher::Evaluator::Predicate::Boolean::And.new(config.subject_filters)
      end

    end # Compiler
  end # Matcher
end # Mutant

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mutant-0.8.24 lib/mutant/matcher/compiler.rb
mutant-0.8.23 lib/mutant/matcher/compiler.rb
mutant-0.8.22 lib/mutant/matcher/compiler.rb
mutant-0.8.21 lib/mutant/matcher/compiler.rb
mutant-0.8.20 lib/mutant/matcher/compiler.rb
mutant-0.8.19 lib/mutant/matcher/compiler.rb
mutant-0.8.18 lib/mutant/matcher/compiler.rb
mutant-0.8.17 lib/mutant/matcher/compiler.rb