Class: UffizziCore::ComposeFile::ConfigOptionService

Inherits:
Object
  • Object
show all
Defined in:
app/services/uffizzi_core/compose_file/config_option_service.rb

Class Method Summary collapse

Class Method Details

.config_options(compose_data) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'app/services/uffizzi_core/compose_file/config_option_service.rb', line 13

def config_options(compose_data)
  compose_data.each_with_object([]) do |(key, value), keys|
    if compose_data.equal?(value)
      raise UffizziCore::ComposeFile::ParseError, I18n.t('compose.infinite_recursion', key: key)
    end

    keys << key
    keys.concat(config_options(value)) if value.is_a?(Hash)
  end
end

.continuous_preview_option(compose_data) ⇒ Object



34
35
36
37
38
39
# File 'app/services/uffizzi_core/compose_file/config_option_service.rb', line 34

def continuous_preview_option(compose_data)
  compose_data.dig('x-uffizzi', 'continuous_preview').presence ||
    compose_data.dig('x-uffizzi', 'continuous_previews').presence ||
    compose_data['x-uffizzi-continuous-preview'].presence ||
    compose_data['x-uffizzi-continuous-previews'].presence
end

.ingress_option(compose_data) ⇒ Object



30
31
32
# File 'app/services/uffizzi_core/compose_file/config_option_service.rb', line 30

def ingress_option(compose_data)
  compose_data.dig('x-uffizzi', 'ingress').presence || compose_data['x-uffizzi-ingress'].presence
end

.prepare_file_path_value(file_path) ⇒ Object



24
25
26
27
28
# File 'app/services/uffizzi_core/compose_file/config_option_service.rb', line 24

def prepare_file_path_value(file_path)
  pathname = Pathname.new(file_path)

  pathname.cleanpath.to_s.strip.delete_prefix('/')
end

.valid_option_format?(option) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
# File 'app/services/uffizzi_core/compose_file/config_option_service.rb', line 5

def valid_option_format?(option)
  if option.is_a?(TrueClass) || option.is_a?(FalseClass)
    raise UffizziCore::ComposeFile::ParseError, I18n.t('compose.boolean_option', value: option)
  end

  option.match(/^[a-zA-Z_][a-zA-Z0-9._\-]+$/).present?
end