Sha256: 77171fd3e67b69f5163059afeb1b529fec1295bfcd7a187a3aa0cc1dd97effd9

Contents?: true

Size: 824 Bytes

Versions: 13

Compression:

Stored size: 824 Bytes

Contents

module CodeClimate
  module TestReporter

    class CalculateBlob

      def initialize(file_path)
        @file_path = file_path
      end

      def blob_id
        calculate_with_file or calculate_with_git
      end

    private

      def calculate_with_file
        File.open(@file_path, "rb") do |file|
          header = "blob #{file.size}\0"
          content = file.read
          store = header + content

          return Digest::SHA1.hexdigest(store)
        end
      rescue EncodingError
        puts "WARNING: Unable to read #{@file_path}\nUsing git for blob calculation"
        nil
      end

      def calculate_with_git
        output = `git hash-object -t blob #{@file_path}`.chomp
        raise 'ERROR: Failed to calculate blob with git' unless $?.success?

        output
      end

    end

  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
codeclimate-test-reporter-0.5.0 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-0.4.8 lib/code_climate/test_reporter/calculate_blob.rb
construi-0.6.0 vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/calculate_blob.rb
construi-0.5.0 vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/calculate_blob.rb
construi-0.4.0 vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/calculate_blob.rb
construi-0.2.0 vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/calculate_blob.rb
construi-0.1.0 vendor/bundle/ruby/1.9.1/gems/codeclimate-test-reporter-0.4.6/lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-0.4.7 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-0.4.6 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-0.4.5 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-0.4.4 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-0.4.3 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-0.4.2 lib/code_climate/test_reporter/calculate_blob.rb