Class: UffizziCore::ComposeFile::Builders::ContainerConfigFilesBuilderService

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

Class Method Summary collapse

Class Method Details

.build_attributes(config_files_data, dependencies, project) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/uffizzi_core/compose_file/builders/container_config_files_builder_service.rb', line 5

def build_attributes(config_files_data, dependencies, project)
  return [] if config_files_data.empty?

  config_file_sources = dependencies.pluck(:source)
  config_files = project.config_files.with_creation_source(UffizziCore::ConfigFile.creation_source.compose_file)
    .by_source(config_file_sources)

  config_files_data.map do |config_file_data|
    detected_dependency = dependencies.detect { |dependency| dependency[:path] == config_file_data[:source] }
    detected_config_file = config_files.detect { |config_file| config_file.source == detected_dependency[:source] }

    if detected_config_file.nil?
      raise UffizziCore::ComposeFile::BuildError, I18n.t('compose.config_file_not_found', name: config_file_data[:source])
    end

    {
      mount_path: config_file_data[:target],
      config_file_id: detected_config_file.id,
    }
  end
end