Class: SLOCCountScanner
- Inherits:
-
Object
- Object
- SLOCCountScanner
- Defined in:
- lib/pluginscan/reports/sloccount_report/sloccount_scanner.rb
Overview
Responsible for running the ‘sloccount` system command and handling any resulting errors The SLOCCount project is at www.dwheeler.com/sloccount/ and can be installed on OSX using homebrew:
brew install sloccount
Defined Under Namespace
Classes: ArgumentError, Exception, NoDirectory, NoInput, SystemSLOCCount, Unavailable
Instance Method Summary collapse
-
#initialize(system_sloccount = SystemSLOCCount.instance) ⇒ SLOCCountScanner
constructor
A new instance of SLOCCountScanner.
- #scan(directory) ⇒ Object
Constructor Details
#initialize(system_sloccount = SystemSLOCCount.instance) ⇒ SLOCCountScanner
Returns a new instance of SLOCCountScanner.
13 14 15 |
# File 'lib/pluginscan/reports/sloccount_report/sloccount_scanner.rb', line 13 def initialize(system_sloccount = SystemSLOCCount.instance) @system_sloccount = system_sloccount end |
Instance Method Details
#scan(directory) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pluginscan/reports/sloccount_report/sloccount_scanner.rb', line 17 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 'sloccount' command is unavailable. Is it installed and in your path?" unless @system_sloccount.available? fail NoDirectory, "No such directory: '#{directory}'" unless Dir.exist?(directory) result, status = @system_sloccount.call(directory) if status.success? SLOCCount.new(result) else check_for_errors(result) { NullSLOCCount.new } end end |