Sha256: 1d7eabf60f8546355b6a277350b0748275b6bb6ed67699d25c73fcb9ef408b2a

Contents?: true

Size: 1.69 KB

Versions: 5

Compression:

Stored size: 1.69 KB

Contents

module Mutest
  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]
        def self.new(scope, target_method)
          name = target_method.name
          evaluator =
            if scope.include?(Memoizable) && 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,Fixnum}]
            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 # Mutest

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mutest-0.0.6 lib/mutest/matcher/method/instance.rb
mutest-0.0.5 lib/mutest/matcher/method/instance.rb
mutest-0.0.4 lib/mutest/matcher/method/instance.rb
mutest-0.0.3 lib/mutest/matcher/method/instance.rb
mutest-0.0.2 lib/mutest/matcher/method/instance.rb