Class: JayAPI::IDBuilder
- Inherits:
-
Object
- Object
- JayAPI::IDBuilder
- Defined in:
- lib/jay_api/id_builder.rb
Overview
Provides methods to calculate special identifiers for Test Case for Jay.
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#software_version ⇒ Object
readonly
Returns the value of attribute software_version.
-
#test_case_id ⇒ Object
readonly
Returns the value of attribute test_case_id.
Instance Method Summary collapse
-
#initialize(test_case_id: nil, project: nil, software_version: nil, result: nil) ⇒ IDBuilder
constructor
A new instance of IDBuilder.
-
#secure_id ⇒ Array
An array with two elements: - The secure Seed (A Version 4 UUID) - The secure Hash composed by concatenating the Software Version, the secure Seed and the result of the Test Case.
-
#short_id ⇒ String
noinspection RubyNilAnalysis.
Constructor Details
#initialize(test_case_id: nil, project: nil, software_version: nil, result: nil) ⇒ IDBuilder
Returns a new instance of IDBuilder.
13 14 15 16 17 18 |
# File 'lib/jay_api/id_builder.rb', line 13 def initialize(test_case_id: nil, project: nil, software_version: nil, result: nil) @test_case_id = test_case_id @project = project @software_version = software_version @result = result end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
11 12 13 |
# File 'lib/jay_api/id_builder.rb', line 11 def project @project end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
11 12 13 |
# File 'lib/jay_api/id_builder.rb', line 11 def result @result end |
#software_version ⇒ Object (readonly)
Returns the value of attribute software_version.
11 12 13 |
# File 'lib/jay_api/id_builder.rb', line 11 def software_version @software_version end |
#test_case_id ⇒ Object (readonly)
Returns the value of attribute test_case_id.
11 12 13 |
# File 'lib/jay_api/id_builder.rb', line 11 def test_case_id @test_case_id end |
Instance Method Details
#secure_id ⇒ Array
Returns An array with two elements:
-
The secure Seed (A Version 4 UUID)
-
The secure Hash composed by concatenating the Software Version, the secure Seed and the result of the Test Case.
This Secure ID is meant for end-to-end verification of the test results.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jay_api/id_builder.rb', line 39 def secure_id unless software_version && result raise ArgumentError, 'The Software Version (software_version) and the Result ' \ '(result) are required to calculate the Secure ID' end [ uuid = SecureRandom.uuid, Digest::MD5.hexdigest("#{software_version}:#{uuid}:#{result}") ] end |
#short_id ⇒ String
noinspection RubyNilAnalysis
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jay_api/id_builder.rb', line 23 def short_id unless test_case_id && project raise ArgumentError, "The Test Case ID (test_case_id) and the Project's name " \ '(project) are required to calculate the Short ID' end clean_id = test_case_id.downcase.gsub(/[^a-z0-9-]/, '') "#{project.underscore}_#{Digest::SHA1.new.update(clean_id).hexdigest[0...12]}" end |