Sha256: ea9a7c9cff6d00d558d991d9e68fe06e0302fcce6c1902a9ae439dac20826035

Contents?: true

Size: 1.65 KB

Versions: 5

Compression:

Stored size: 1.65 KB

Contents

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

module Hako
  class DefinitionLoader
    def initialize(app, dry_run:)
      @app = app
      @dry_run = dry_run
    end

    def load(tag, with: nil)
      additional_containers = @app.yaml.fetch('additional_containers', {})
      container_names = ['app']
      if with
        container_names.concat(with)
      else
        if @app.yaml.key?('front')
          container_names << 'front'
        end
        container_names.concat(additional_containers.keys)
      end

      load_containers_from_name(tag, container_names, additional_containers)
    end

    private

    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)
            when 'front'
              load_front(@app.yaml['front'], 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

    def load_front(yaml, dry_run:)
      Loader.new(Hako::Fronts, 'hako/fronts').load(yaml.fetch('type')).new(@app, yaml, dry_run: dry_run)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hako-0.12.0 lib/hako/definition_loader.rb
hako-0.11.2 lib/hako/definition_loader.rb
hako-0.11.1 lib/hako/definition_loader.rb
hako-0.11.0 lib/hako/definition_loader.rb
hako-0.10.0 lib/hako/definition_loader.rb