Class: Mago::Detector

Inherits:
Object
  • Object
show all
Defined in:
lib/mago/detector.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_paths = [], options = {}) ⇒ Detector

Returns a new instance of Detector.



3
4
5
6
7
# File 'lib/mago/detector.rb', line 3

def initialize(file_paths = [], options = {})
  @file_paths = file_paths
  @report = Report.new
  @ignore = options[:ignore] || []
end

Instance Method Details

#process_file(path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mago/detector.rb', line 16

def process_file(path)
  code = File.read(path)
  sexp_node = RubyParser.new.parse(code)

  file = Mago::RubyFile.new(path)

  sexp_processor = Mago::SexpProcessor.new(file, @ignore)
  sexp_processor.process sexp_node

  @report.files << file
rescue Errno::ENOENT => err
  @report.errors << err.message
rescue Racc::ParseError => err
  msg = "#{path} has invalid ruby code. " << err.message
  @report.errors << msg
end

#runObject



9
10
11
12
13
14
# File 'lib/mago/detector.rb', line 9

def run
  @file_paths.each do |path|
    process_file(path)
  end
  @report
end