Module: Inferno::DSL::ShortIDManager

Included in:
Entities::TestSuite
Defined in:
lib/inferno/dsl/short_id_manager.rb

Overview

This module manages and locks short IDs, ensuring that short IDs remain stable and do not change unexpectedly.

Instance Method Summary collapse

Instance Method Details

#base_short_id_file_folder(folder = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/inferno/dsl/short_id_manager.rb', line 6

def base_short_id_file_folder(folder = nil)
  folder ||= File.dirname(Object.const_source_location(name).first)

  return folder if File.exist?(File.join(folder, short_id_file_name))

  return folder if File.basename(File.dirname(folder)) == 'lib'

  return folder if File.dirname(folder) == folder

  base_short_id_file_folder(File.dirname(folder))
end

#current_short_id_mapHash

Builds and memoizes the current mapping of runnable IDs to their short IDs.

Returns:

  • (Hash)

    current short ID mapping



56
57
58
59
60
61
# File 'lib/inferno/dsl/short_id_manager.rb', line 56

def current_short_id_map
  @current_short_id_map ||=
    all_descendants.each_with_object({}) do |runnable, mapping|
      mapping[runnable.id] = runnable.short_id
    end
end

#short_id_file_nameObject



18
19
20
# File 'lib/inferno/dsl/short_id_manager.rb', line 18

def short_id_file_name
  "#{name.demodulize.underscore}_short_id_map.yml"
end

#short_id_file_pathObject



22
23
24
25
# File 'lib/inferno/dsl/short_id_manager.rb', line 22

def short_id_file_path
  @short_id_file_path =
    File.join(base_short_id_file_folder, short_id_file_name).freeze
end

#short_id_mapHash

Loads and memoizes the short ID map from the YAML file.

Returns:

  • (Hash)

    mapping of runnable IDs to their locked short IDs



30
31
32
33
34
# File 'lib/inferno/dsl/short_id_manager.rb', line 30

def short_id_map
  return unless File.exist?(short_id_file_path)

  @short_id_map ||= YAML.load_file(short_id_file_path)
end