Class: Dragnet::Exporters::IDGenerator

Inherits:
Object
  • Object
show all
Includes:
Helpers::RepositoryHelper
Defined in:
lib/dragnet/exporters/id_generator.rb

Overview

Generates unique IDs for the Manual Test Records by hashing some of their properties into a hexadecimal SHA1.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::RepositoryHelper

#relative_to_repo, #repo_base, #shorten_sha1

Constructor Details

#initialize(repository) ⇒ IDGenerator

Returns a new instance of IDGenerator.

Parameters:

  • repository (Dragnet::Repository)

    The repository where the MTR files are located. This allows the SHA1 to be calculated with relative paths to the MTRs' files.



19
20
21
# File 'lib/dragnet/exporters/id_generator.rb', line 19

def initialize(repository)
  @repository = repository
end

Instance Attribute Details

#repositoryObject (readonly)

Returns the value of attribute repository.



14
15
16
# File 'lib/dragnet/exporters/id_generator.rb', line 14

def repository
  @repository
end

Instance Method Details

#id_for(test_record) ⇒ String

Calculates the ID of the given MTR :reek:FeatureEnvy (Cannot be done in the TestRecord itself because it needs the Repository)

Parameters:

Returns:

  • (String)

    The ID for the given TestRecord.



28
29
30
31
32
# File 'lib/dragnet/exporters/id_generator.rb', line 28

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