Sha256: 744fa86df6d9f826f060bd67ecd43a57bd315719c645cc832d042b1973b4b91e

Contents?: true

Size: 1.37 KB

Versions: 33

Compression:

Stored size: 1.37 KB

Contents

# encoding: utf-8

module Mutant
  class Matcher
    class Method

      # Visitor to find last match inside AST
      class Finder

        # Run finder
        #
        # @param [Parser::AST::Node]
        #
        # @return [Parser::AST::Node]
        #   if found
        #
        # @return [nil]
        #   otherwise
        #
        # @api private
        #
        #
        def self.run(root, &predicate)
          new(root, predicate).match
        end

        private_class_method :new

        # Return match
        #
        # @return [Parser::AST::Node]
        #
        # @api private
        #
        attr_reader :match

      private

        # Initialize object
        #
        # @param [Parer::AST::Node]
        #
        # @return [undefined]
        #
        # @api private
        #
        #
        def initialize(root, predicate)
          @root, @predicate = root, predicate
          visit(root)
        end

        # Visit node
        #
        # @param [Parser::AST::Node] node
        #
        # @return [undefined]
        #
        # @api private
        #
        def visit(node)
          if @predicate.call(node)
            @match = node
          end

          node.children.each do |child|
            visit(child) if child.kind_of?(Parser::AST::Node)
          end
        end

      end # Finder
    end # Method
  end # Matcher
end # Mutant

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
mutant-0.3.6 lib/mutant/matcher/method/finder.rb
mutant-0.3.5 lib/mutant/matcher/method/finder.rb
mutant-0.3.4 lib/mutant/matcher/method/finder.rb
mutant-0.3.3 lib/mutant/matcher/method/finder.rb
mutant-0.3.2 lib/mutant/matcher/method/finder.rb
mutant-0.3.1 lib/mutant/matcher/method/finder.rb
mutant-0.3.0 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.rc5 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.rc4 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.rc3 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.rc2 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.rc1 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta22 lib/mutant/matcher/method/finder.rb