Class: UffizziCore::ComposeFile::Parsers::NamedVolumesParserService

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

Constant Summary collapse

VALID_VOLUME_NAME_REGEX =
/^[a-zA-Z0-9._-]+$/.freeze

Class Method Summary collapse

Class Method Details

.parse(volumes_data) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/services/uffizzi_core/compose_file/parsers/named_volumes_parser_service.rb', line 7

def parse(volumes_data)
  return [] if volumes_data.nil?

  raise UffizziCore::ComposeFile::ParseError, I18n.t('compose.invalid_type', option: :volumes) unless volumes_data.is_a?(Hash)

  volume_names = volumes_data.keys
  volume_names.each do |volume_name|
    unless volume_name.match?(VALID_VOLUME_NAME_REGEX)
      raise UffizziCore::ComposeFile::ParseError,
            I18n.t('compose.volume_invalid_name', name: volume_name)
    end
  end

  volume_names
end