Sha256: 7cb17817d9b52e0af616626c6d3bc412e47d6ea7c69d40eaea64fdc6e0b4681a

Contents?: true

Size: 1.4 KB

Versions: 8

Compression:

Stored size: 1.4 KB

Contents

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.16 lib/mutant/matcher/compiler.rb
mutant-0.8.15 lib/mutant/matcher/compiler.rb
mutant-0.8.14 lib/mutant/matcher/compiler.rb
mutant-0.8.13 lib/mutant/matcher/compiler.rb
mutant-0.8.12 lib/mutant/matcher/compiler.rb
mutant-0.8.11 lib/mutant/matcher/compiler.rb
mutant-0.8.10 lib/mutant/matcher/compiler.rb
mutant-0.8.9 lib/mutant/matcher/compiler.rb