Sha256: 8e40cd0fc6eaa11df1c020904359e86079dd759471a557b6ba3f19bc0437c66b

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

require 'digest'

require_relative '../helpers/repository_helper'

module Dragnet
  module Exporters
    # Generates unique IDs for the Manual Test Records by hashing some of their
    # properties into a hexadecimal SHA1.
    class IDGenerator
      include Dragnet::Helpers::RepositoryHelper

      attr_reader :repository

      # @param [Dragnet::Repository] repository The repository where the MTR
      #   files are located. This allows the SHA1 to be calculated with relative
      #   paths to the MTRs' files.
      def initialize(repository)
        @repository = repository
      end

      # Calculates the ID of the given MTR
      # @param [Dragnet::TestRecord] test_record The record for which the ID
      #   should be calculated.
      # @return [String] The ID for the given +TestRecord+.
      # :reek:FeatureEnvy (Cannot be done in the TestRecord itself because it needs the Repository)
      def id_for(test_record)
        string = "#{relative_to_repo(test_record.source_file)}#{test_record.id}"
        # noinspection RubyMismatchedReturnType (This is never nil)
        Digest::SHA1.hexdigest(string)[0...16]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dragnet-5.3.1 lib/dragnet/exporters/id_generator.rb
dragnet-5.3.0 lib/dragnet/exporters/id_generator.rb
dragnet-5.2.1 lib/dragnet/exporters/id_generator.rb