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
-
#assign_short_ids ⇒ void
Assigns locked short IDs to all descendant runnables based on the short ID map.
- #base_short_id_file_folder(folder = nil) ⇒ Object
-
#current_short_id_map ⇒ Hash
Builds and memoizes the current mapping of runnable IDs to their short IDs.
- #short_id_file_name ⇒ Object
- #short_id_file_path ⇒ Object
-
#short_id_map ⇒ Hash
Loads and memoizes the short ID map from the YAML file.
Instance Method Details
#assign_short_ids ⇒ void
This method returns an undefined value.
Assigns locked short IDs to all descendant runnables based on the short ID map.
This method is called at boot time.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/inferno/dsl/short_id_manager.rb', line 42 def assign_short_ids return unless short_id_map all_descendants.each do |runnable| new_short_id = short_id_map.fetch(runnable.id) runnable.short_id(new_short_id) rescue KeyError Inferno::Application['logger'].warn("No short id defined for #{runnable.id}") end end |
#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_map ⇒ Hash
Builds and memoizes the current mapping of runnable IDs to their short IDs.
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_name ⇒ Object
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_path ⇒ Object
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_map ⇒ Hash
Loads and memoizes the short ID map from the YAML file.
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 |