Class: AxR::Runner
- Inherits:
-
Object
- Object
- AxR::Runner
- Defined in:
- lib/axr/runner.rb
Constant Summary collapse
- DOT_RB =
'.rb'
Instance Attribute Summary collapse
-
#exit_on_warnings ⇒ Object
(also: #exit_on_warnings?)
readonly
Returns the value of attribute exit_on_warnings.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
- #files_to_scan ⇒ Object
-
#initialize(target = nil, formatter: AxR::Formatters::Default.new, exit_on_warnings: false) ⇒ Runner
constructor
A new instance of Runner.
- #invoke ⇒ Object
Constructor Details
#initialize(target = nil, formatter: AxR::Formatters::Default.new, exit_on_warnings: false) ⇒ Runner
Returns a new instance of Runner.
12 13 14 15 16 |
# File 'lib/axr/runner.rb', line 12 def initialize(target = nil, formatter: AxR::Formatters::Default.new, exit_on_warnings: false) @target = target @formatter = formatter @exit_on_warnings = exit_on_warnings end |
Instance Attribute Details
#exit_on_warnings ⇒ Object (readonly) Also known as: exit_on_warnings?
Returns the value of attribute exit_on_warnings.
10 11 12 |
# File 'lib/axr/runner.rb', line 10 def exit_on_warnings @exit_on_warnings end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
10 11 12 |
# File 'lib/axr/runner.rb', line 10 def formatter @formatter end |
#target ⇒ Object (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_scan ⇒ Object
35 36 37 |
# File 'lib/axr/runner.rb', line 35 def files_to_scan @files_to_scan ||= scan_single_file? ? [target] : Dir.glob("#{target_dir}**/*#{DOT_RB}") end |
#invoke ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/axr/runner.rb', line 20 def invoke files_with_warnings = files_to_scan.each_with_object({}) do |file_path, issues| scan_result = AxR::Scanner.new(source: File.open(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 exit_on_warnings? && files_with_warnings.any? files_with_warnings end |