Class: CemAcpt::ImageNameBuilder
- Inherits:
-
Object
- Object
- CemAcpt::ImageNameBuilder
- Includes:
- Logging
- Defined in:
- lib/cem_acpt/image_name_builder.rb
Overview
Dynamically builds an image name based on parameters specified in the config. The config is expected to have a key ‘image_name_builder’ with the following options:
- 'parts' - (Required) An array of strings to be joined together to form the image name.
If the strings begin with a '$', they will be replaced with the corresponding
value from current test data. To specify nested keys, use '.' to separate
the keys. Example: '$name.pattern.framework' will be replaced with the
value of the name pattern key framework in the current test data.
- 'join_with' - (Optional) The string to join the parts with. Defaults to ''.
- 'character_substitutions' - (Optional) An array of of 2-item arrays. The first item
is the character to replace, the second is the replacement.
Example: [[' ', '-'], ['_', '-']] will replace all spaces
and underscores with dashes.
- 'validation_pattern' - (Optional) A regex pattern to validate the image name against.
Constant Summary
Constants included from Logging
Instance Method Summary collapse
-
#build(test_data) ⇒ String
Builds an image name based on the config.
-
#initialize(config) ⇒ ImageNameBuilder
constructor
Initializes the ImageNameBuilder.
Methods included from Logging
current_log_config, #current_log_config, current_log_format, #current_log_format, #current_log_level, current_log_level, included, #logger, logger, new_log_config, #new_log_config, new_log_formatter, #new_log_formatter, #new_log_level, new_log_level, #new_logger, new_logger, verbose?, #verbose?
Constructor Details
#initialize(config) ⇒ ImageNameBuilder
Initializes the ImageNameBuilder.
27 28 29 30 31 32 33 |
# File 'lib/cem_acpt/image_name_builder.rb', line 27 def initialize(config) unless config.has?('image_name_builder') raise ArgumentError, 'Configuration does not have an image_name_builder key' end @config = config.get('image_name_builder') end |
Instance Method Details
#build(test_data) ⇒ String
Builds an image name based on the config. It does so in three steps:
1. Resolve variables in the parts array.
2. Join the parts together with the join_with string if specified
and validate the image name against the validation_pattern if
specified.
3. Perform any specified character substitutions on the image name.
43 44 45 46 47 48 49 |
# File 'lib/cem_acpt/image_name_builder.rb', line 43 def build(test_data) parts = resolve_parts(test_data) image_name = create_image_name(parts) final_image_name = character_substitutions(image_name) logger.debug "Final image name: #{final_image_name}" final_image_name end |