class RubyLint::FileLoader

{RubyLint::FileLoader} iterates over an AST and given a constant node will try to find the corresponding filepath using {RubyLint::FileScanner}.

## Options

The following options must be set when creating an instance of this class:

@!attribute [r] file_scanner

@return [RubyLint::FileScanner]

@!attribute [r] parser

@return [RubyLint::Parser]

@!attribute [r] nodes

@return [Array] A list of extra nodes (and their comments) a VM instance
 should process before processing the file being analyzed.

@!attribute [r] paths

@return [Set]

Attributes

comments[R]
file_scanner[R]
nodes[R]
parser[R]
paths[R]

Public Instance Methods

after_initialize() click to toggle source

Called after a new instance of this class is created.

# File lib/ruby-lint/file_loader.rb, line 32
def after_initialize
  @file_scanner = FileScanner.new(@directories, @ignore_paths)
  @parser       = Parser.new
  @nodes        = []
  @paths        = Set.new
end
on_const(node) click to toggle source

@param [RubyLint::AST::Node] node

# File lib/ruby-lint/file_loader.rb, line 42
def on_const(node)
  const_path = ConstantPath.new(node)

  files      = file_scanner.scan(const_path.to_s)
  last_name  = const_path.constant_segments.last.last

  paths << node.file

  files.each do |path|
    next if paths.include?(path)

    paths << path

    process_file(last_name, path)
  end
end

Private Instance Methods

process_file(constant_name, path) click to toggle source

@param [String] constant_name @param [String] path

# File lib/ruby-lint/file_loader.rb, line 65
def process_file(constant_name, path)
  code = File.read(path)

  return unless code.include?(constant_name)

  ast, comments = parser.parse(code, path)

  iterate(ast)

  nodes << [ast, comments]
end