Sha256: 8db48dfc5db9463aa980df643d167b737c36e977a9e523cabf750c4f4e107596

Contents?: true

Size: 1.35 KB

Versions: 24

Compression:

Stored size: 1.35 KB

Contents

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

24 entries across 24 versions & 1 rubygems

Version Path
mutant-0.5.26 lib/mutant/matcher/method/finder.rb
mutant-0.5.25 lib/mutant/matcher/method/finder.rb
mutant-0.5.24 lib/mutant/matcher/method/finder.rb
mutant-0.5.23 lib/mutant/matcher/method/finder.rb
mutant-0.5.22 lib/mutant/matcher/method/finder.rb
mutant-0.5.21 lib/mutant/matcher/method/finder.rb
mutant-0.5.20 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta21 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta20 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta19 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta18 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta17 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta16 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta15 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta14 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta13 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta12 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta11 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta10 lib/mutant/matcher/method/finder.rb
mutant-0.3.0.beta9 lib/mutant/matcher/method/finder.rb