Class: AxR::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/axr/runner.rb

Constant Summary collapse

DOT_RB =
'.rb'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target = nil, formatter: AxR::Formatters::Default.new) ⇒ Runner

Returns a new instance of Runner.



12
13
14
15
# File 'lib/axr/runner.rb', line 12

def initialize(target = nil, formatter: AxR::Formatters::Default.new)
  @target    = target
  @formatter = formatter
end

Instance Attribute Details

#formatterObject (readonly)

Returns the value of attribute formatter.



10
11
12
# File 'lib/axr/runner.rb', line 10

def formatter
  @formatter
end

#targetObject (readonly)

Returns the value of attribute target.



10
11
12
# File 'lib/axr/runner.rb', line 10

def target
  @target
end

Instance Method Details

#files_to_scanObject



31
32
33
34
35
36
37
# File 'lib/axr/runner.rb', line 31

def files_to_scan
  @files_to_scan ||= if scan_single_file?
                       [target]
                     else
                       Dir.glob("#{target_dir}**/*.rb")
                     end
end

#invokeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/axr/runner.rb', line 17

def invoke
  files_with_warnings = files_to_scan.each_with_object({}) do |file_path, issues|
    scan_result = AxR::Scanner.new(file_path: file_path).scan
    issues[file_path] = scan_result.warnings if scan_result.warnings.any?
    formatter.single_file(scan_result, file_path)
  end

  formatter.summary(files_to_scan, files_with_warnings)

  # exit 1 if files_with_warnings.any?

  files_with_warnings
end