# A thin wrapper around the `cloc` system call # The CLOC project is at http://cloc.sourceforge.net/ and can be installed on OSX using homebrew: # brew install cloc # # DANGER: not covered by tests class SystemCloc def initialize(command_name = 'cloc') @command_name = command_name end def which # DANGER!!! calling system command Open3.capture2("which #{@command_name}") end def call(directory) # DANGER!!! calling system command # Should be safe from injection because of the `Dir.exist?` check. Open3.capture2("#{@command_name} --csv --quiet #{directory} 2> #{error_log_name}") ensure delete_empty_error_log end private def error_log_name "#{@command_name}_error.log" end def delete_empty_error_log File.delete(error_log_name) if File.zero?(error_log_name) end end