Sha256: 2f5f951d965af0be2b5330c09c3bf08bf2d64037fa2f900658f583b549972821

Contents?: true

Size: 1.2 KB

Versions: 28

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Mutant
  # Abstract matcher to find subjects to mutate
  class Matcher
    include Adamantium::Flat, AbstractType

    # Call matcher
    #
    # @param [Env] env
    #
    # @return [Enumerable<Subject>]
    #
    abstract_method :call

    # Turn config into matcher
    #
    # @param [Config] config
    #
    # @return [Matcher]
    def self.from_config(config)
      Filter.new(
        Chain.new(config.match_expressions.map(&:matcher)),
        method(:allowed_subject?).curry.call(config)
      )
    end

    def self.allowed_subject?(config, subject)
      select_subject?(config, subject) && !ignore_subject?(config, subject)
    end
    private_class_method :allowed_subject?

    def self.select_subject?(config, subject)
      config.subject_filters.all? { |filter| filter.call(subject) }
    end
    private_class_method :select_subject?

    # Predicate that tests for ignored subject
    #
    # @param [Config] config
    # @param [Subject] subject
    #
    # @return [Boolean]
    def self.ignore_subject?(config, subject)
      config.ignore_expressions.any? do |expression|
        expression.prefix?(subject.expression)
      end
    end
  end # Matcher
end # Mutant

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
mutant-0.10.23 lib/mutant/matcher.rb
mutant-0.10.22 lib/mutant/matcher.rb
mutant-0.10.21 lib/mutant/matcher.rb
mutant-0.10.20 lib/mutant/matcher.rb
mutant-0.10.19 lib/mutant/matcher.rb
mutant-0.10.18 lib/mutant/matcher.rb
mutant-0.10.17 lib/mutant/matcher.rb
mutant-0.10.16 lib/mutant/matcher.rb
mutant-0.10.15 lib/mutant/matcher.rb
mutant-0.10.14 lib/mutant/matcher.rb
mutant-0.10.13 lib/mutant/matcher.rb
mutant-0.10.12 lib/mutant/matcher.rb
mutant-0.10.11 lib/mutant/matcher.rb
mutant-0.10.10 lib/mutant/matcher.rb
mutant-0.10.9 lib/mutant/matcher.rb
mutant-0.10.8 lib/mutant/matcher.rb
mutant-0.10.7 lib/mutant/matcher.rb
mutant-0.10.6 lib/mutant/matcher.rb
mutant-0.10.5 lib/mutant/matcher.rb
mutant-0.10.4 lib/mutant/matcher.rb