Sha256: e344712991683a28e7066a922d327c221d9918209f8a8f0c258f0d45c37fd84e

Contents?: true

Size: 1.57 KB

Versions: 11

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

module Mutant
  class Matcher
    class Method
      # Matcher for instance methods
      class Instance < self

        # Dispatching builder, detects memoizable case
        #
        # @param [Class, Module] scope
        # @param [UnboundMethod] method
        #
        # @return [Matcher::Method::Instance]
        #
        # :reek:ManualDispatch
        def self.new(scope, target_method)
          name = target_method.name
          evaluator =
            if scope.respond_to?(:memoized?) && scope.memoized?(name)
              Evaluator::Memoized
            else
              Evaluator
            end

          super(scope, target_method, evaluator)
        end

        # Instance method specific evaluator
        class Evaluator < Evaluator
          SUBJECT_CLASS = Subject::Method::Instance
          NAME_INDEX    = 0

        private

          def match?(node)
            n_def?(node)                           &&
            node.location.line.equal?(source_line) &&
            node.children.fetch(NAME_INDEX).equal?(method_name)
          end

          # Evaluator specialized for memoized instance methods
          class Memoized < self
            SUBJECT_CLASS = Subject::Method::Instance::Memoized

          private

            def source_location
              scope
                .unmemoized_instance_method(method_name)
                .source_location
            end

          end # Memoized
        end # Evaluator

        private_constant(*constants(false))
      end # Instance
    end # Method
  end # Matcher
end # Mutant

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mutant-0.10.6 lib/mutant/matcher/method/instance.rb
mutant-0.10.5 lib/mutant/matcher/method/instance.rb
mutant-0.10.4 lib/mutant/matcher/method/instance.rb
mutant-0.10.1 lib/mutant/matcher/method/instance.rb
mutant-0.10.0 lib/mutant/matcher/method/instance.rb
mutant-0.9.14 lib/mutant/matcher/method/instance.rb
mutant-0.9.13 lib/mutant/matcher/method/instance.rb
mutant-0.9.12 lib/mutant/matcher/method/instance.rb
mutant-0.9.11 lib/mutant/matcher/method/instance.rb
mutant-0.9.10 lib/mutant/matcher/method/instance.rb
mutant-0.9.9 lib/mutant/matcher/method/instance.rb