Sha256: 43dffa6e4b3597dbe66103e6ada420ed525b4018821cda9771d63eb756a42b13

Contents?: true

Size: 1.64 KB

Versions: 30

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true
require 'set'
require 'hako/app_container'
require 'hako/container'
require 'hako/loader'

module Hako
  class DefinitionLoader
    # @param [Application] app
    # @param [Boolean] dry_run
    def initialize(app, dry_run:)
      @app = app
      @dry_run = dry_run
    end

    # @param [String] tag
    # @param [Array<String>, nil] with
    # @return [Hash<String, Container>]
    def load(tag, with: nil)
      additional_containers = @app.yaml.fetch('additional_containers', {})
      container_names = ['app']
      if with
        container_names.concat(with)
      else
        container_names.concat(additional_containers.keys)
      end

      load_containers_from_name(tag, container_names, additional_containers)
    end

    private

    # @param [String] tag
    # @param [Array<String>] container_names
    # @param [Hash<String, Hash>] additional_containers
    # @return [Hash<String, Container>]
    def load_containers_from_name(tag, container_names, additional_containers)
      names = Set.new(container_names)
      containers = {}
      while containers.size < names.size
        names.difference(containers.keys).each do |name|
          containers[name] =
            case name
            when 'app'
              AppContainer.new(@app, @app.yaml['app'].merge('tag' => tag), dry_run: @dry_run)
            else
              Container.new(@app, additional_containers.fetch(name), dry_run: @dry_run)
            end

          containers[name].links.each do |link|
            m = link.match(/\A([^:]+):([^:]+)\z/)
            names << (m ? m[1] : link)
          end
        end
      end
      containers
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
hako-1.1.0 lib/hako/definition_loader.rb
hako-1.0.1 lib/hako/definition_loader.rb
hako-1.0.0 lib/hako/definition_loader.rb
hako-0.27.0 lib/hako/definition_loader.rb
hako-0.26.0 lib/hako/definition_loader.rb
hako-0.25.2 lib/hako/definition_loader.rb
hako-0.25.1 lib/hako/definition_loader.rb
hako-0.25.0 lib/hako/definition_loader.rb
hako-0.24.0 lib/hako/definition_loader.rb
hako-0.23.0 lib/hako/definition_loader.rb
hako-0.22.0 lib/hako/definition_loader.rb
hako-0.21.1 lib/hako/definition_loader.rb
hako-0.21.0 lib/hako/definition_loader.rb
hako-0.20.3 lib/hako/definition_loader.rb
hako-0.20.2 lib/hako/definition_loader.rb
hako-0.20.1 lib/hako/definition_loader.rb
hako-0.20.0 lib/hako/definition_loader.rb
hako-0.19.0 lib/hako/definition_loader.rb
hako-0.18.1 lib/hako/definition_loader.rb
hako-0.18.0 lib/hako/definition_loader.rb