Sha256: 08fb9a0bc691e6ad331f9618b5590d77a19a1a3e9c6339080d08e49f29dcf74a

Contents?: true

Size: 1.9 KB

Versions: 10

Compression:

Stored size: 1.9 KB

Contents

module Mutant
  class Matcher
    class Method
      # Matcher for instance methods
      class Instance < self
        SUBJECT_CLASS = Subject::Method::Instance

        # Dispatching builder, detects memoizable case
        #
        # @param [Env] env
        # @param [Class, Module] scope
        # @param [UnboundMethod] method
        #
        # @return [Matcher::Method::Instance]
        #
        # @api private
        #
        def self.build(env, scope, target_method)
          name = target_method.name
          if scope.ancestors.include?(::Memoizable) && scope.memoized?(name)
            return Memoized.new(env, scope, target_method)
          end
          super
        end

        # Return identification
        #
        # @return [String]
        #
        # @api private
        #
        def identification
          "#{scope.name}##{method_name}"
        end
        memoize :identification

        NAME_INDEX = 0

      private

        # Check if node is matched
        #
        # @param [Parser::AST::Node] node
        #
        # @return [Boolean]
        #
        # @api private
        #
        def match?(node)
          location   = node.location       || return
          expression = location.expression || return

          expression.line.equal?(source_line)           &&
          node.type.equal?(:def)                        &&
          node.children[NAME_INDEX].equal?(method_name)
        end

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

        private

          # Return source location
          #
          # @return [Array]
          #
          # @api private
          #
          def source_location
            scope.unmemoized_instance_method(method_name).source_location
          end

        end # Memoized

      end # Instance
    end # Method
  end # Matcher
end # Mutant

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mutant-0.7.4 lib/mutant/matcher/method/instance.rb
mutant-0.7.3 lib/mutant/matcher/method/instance.rb
mutant-0.7.2 lib/mutant/matcher/method/instance.rb
mutant-0.7.1 lib/mutant/matcher/method/instance.rb
mutant-0.6.7 lib/mutant/matcher/method/instance.rb
mutant-0.6.6 lib/mutant/matcher/method/instance.rb
mutant-0.6.5 lib/mutant/matcher/method/instance.rb
mutant-0.6.4 lib/mutant/matcher/method/instance.rb
mutant-0.6.3 lib/mutant/matcher/method/instance.rb
mutant-0.6.2 lib/mutant/matcher/method/instance.rb