class Coverband::Utils::MethodDefinitionScanner
Attributes
path[R]
Public Class Methods
new(path)
click to toggle source
# File lib/coverband/utils/method_definition_scanner.rb, line 9 def initialize(path) @path = path end
scan(path)
click to toggle source
# File lib/coverband/utils/method_definition_scanner.rb, line 17 def self.scan(path) new(path).scan end
Public Instance Methods
scan()
click to toggle source
# File lib/coverband/utils/method_definition_scanner.rb, line 13 def scan scan_node(RubyVM::AbstractSyntaxTree.parse_file(path), nil) end
Private Instance Methods
scan_children(node, current_class)
click to toggle source
# File lib/coverband/utils/method_definition_scanner.rb, line 88 def scan_children(node, current_class) node.children.flatten.compact.map { |child| scan_node(child, current_class) }.flatten end
scan_node(node, class_name)
click to toggle source
# File lib/coverband/utils/method_definition_scanner.rb, line 71 def scan_node(node, class_name) definitions = [] return definitions unless node.is_a?(RubyVM::AbstractSyntaxTree::Node) current_class = node.type == :CLASS ? node.children.first.children.last : class_name if node.type == :DEFN definitions << MethodDefinition.new( first_line_number: node.first_lineno, last_line_number: node.last_lineno, name: node.children.first, class_name: current_class, file_path: path ) end definitions + scan_children(node, current_class) end