Class: CLOCScanner
- Inherits:
-
Object
- Object
- CLOCScanner
- Defined in:
- lib/pluginscan/reports/cloc_report/cloc_scanner.rb
Overview
Responsible for running the cloc system command and handling any resulting errors
Defined Under Namespace
Classes: ArgumentError, CSVError, Exception, NoDirectory, Unavailable
Instance Method Summary collapse
-
#initialize(system_cloc = SystemCloc.new) ⇒ CLOCScanner
constructor
A new instance of CLOCScanner.
- #scan(directory) ⇒ Object
Constructor Details
#initialize(system_cloc = SystemCloc.new) ⇒ CLOCScanner
Returns a new instance of CLOCScanner.
11 12 13 |
# File 'lib/pluginscan/reports/cloc_report/cloc_scanner.rb', line 11 def initialize(system_cloc = SystemCloc.new) @system_cloc = system_cloc end |
Instance Method Details
#scan(directory) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pluginscan/reports/cloc_report/cloc_scanner.rb', line 15 def scan(directory) fail ArgumentError, "directory must must be a string (or quack like a string)" unless directory.respond_to?(:to_str) fail Unavailable, "The 'cloc' command is unavailable. Is it installed and in your path?" unless cloc_available? fail NoDirectory, "No such directory: '#{directory}'" unless Dir.exist?(directory) result, status = @system_cloc.call(directory) if status.success? CLOC.new(cloc_csv(result)) else raise Exception, "CLOC raised an error we didn't recognise. Here's the output:\n#{result}" end end |