Sha256: 1094d549ce5e519d0e30cb718d0b7c22f4c029dddde1fdef48361382b48a7bee

Contents?: true

Size: 837 Bytes

Versions: 1

Compression:

Stored size: 837 Bytes

Contents

# 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pluginscan-0.9.0 lib/pluginscan/reports/cloc_report/system_cloc.rb