Sha256: 9848fccdf2d39d1bbea5fe2584f3626e818ab6f25f4e21537fdab624a1c987de

Contents?: true

Size: 822 Bytes

Versions: 19

Compression:

Stored size: 822 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

19 entries across 19 versions & 2 rubygems

Version Path
codeclimate-test-reporter-1.0.9 lib/code_climate/test_reporter/calculate_blob.rb
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/calculate_blob.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/calculate_blob.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/calculate_blob.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/calculate_blob.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/calculate_blob.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/calculate_blob.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/codeclimate-test-reporter-1.0.8/lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-1.0.8 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-1.0.7 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-1.0.6 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-1.0.5 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-1.0.4 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-1.0.3 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-1.0.2 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-1.0.1 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-1.0.0 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-1.0.0.pre.rc2 lib/code_climate/test_reporter/calculate_blob.rb
codeclimate-test-reporter-1.0.0.pre.rc1 lib/code_climate/test_reporter/calculate_blob.rb