Sha256: a7277af1dd8351e9d9c1bdb1ecaab7fb4365b5d116b11bf20f49647d130f3f9d

Contents?: true

Size: 1.79 KB

Versions: 15

Compression:

Stored size: 1.79 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

          # Check if node is matched
          #
          # @param [Parser::AST::Node] node
          #
          # @return [Boolean]
          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

            # Source location
            #
            # @return [Array{String,Integer}]
            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

15 entries across 15 versions & 1 rubygems

Version Path
mutant-0.9.8 lib/mutant/matcher/method/instance.rb
mutant-0.9.7 lib/mutant/matcher/method/instance.rb
mutant-0.9.6 lib/mutant/matcher/method/instance.rb
mutant-0.9.5 lib/mutant/matcher/method/instance.rb
mutant-0.9.4 lib/mutant/matcher/method/instance.rb
mutant-0.9.3 lib/mutant/matcher/method/instance.rb
mutant-0.9.2 lib/mutant/matcher/method/instance.rb
mutant-0.9.1 lib/mutant/matcher/method/instance.rb
mutant-0.9.0 lib/mutant/matcher/method/instance.rb
mutant-0.8.24 lib/mutant/matcher/method/instance.rb
mutant-0.8.23 lib/mutant/matcher/method/instance.rb
mutant-0.8.22 lib/mutant/matcher/method/instance.rb
mutant-0.8.21 lib/mutant/matcher/method/instance.rb
mutant-0.8.20 lib/mutant/matcher/method/instance.rb
mutant-0.8.19 lib/mutant/matcher/method/instance.rb