Sha256: 7e300248e0951fe9762066e7a43a8b6691aacc372bc43fdeff47a19ccca50bc6

Contents?: true

Size: 1.4 KB

Versions: 6

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Orchestration
  module DockerCompose
    class Configuration
      def initialize(env, environment, selected_services)
        @env = env # Global environment
        @environment = environment # Current build environment
        @selected_services = selected_services
      end

      def version
        @env.docker_api_version
      end

      def services
        Hash[services_enabled]
      end

      def volumes
        {}.merge(database_volume).merge(mongo_volume)
      end

      private

      def services_available
        {
          app: AppService,
          database: DatabaseService,
          mongo: MongoService,
          rabbitmq: RabbitMQService,
          haproxy: HAProxyService
        }
      end

      def services_enabled
        @selected_services.map do |service, config|
          definition = service_definition(service, config)
          next if definition.nil?

          [service.to_s, definition]
        end.compact
      end

      def database_volume
        return {} unless services.key?('database')

        { @env.database_volume => {} }
      end

      def mongo_volume
        return {} unless services.key?('mongo')

        { @env.mongo_volume => {} }
      end

      def service_definition(service, config)
        services_available
          .fetch(service)
          .new(config, @environment)
          .definition
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
orchestration-0.3.14 lib/orchestration/docker_compose/configuration.rb
orchestration-0.3.13 lib/orchestration/docker_compose/configuration.rb
orchestration-0.3.12 lib/orchestration/docker_compose/configuration.rb
orchestration-0.3.11 lib/orchestration/docker_compose/configuration.rb
orchestration-0.3.10 lib/orchestration/docker_compose/configuration.rb
orchestration-0.3.9 lib/orchestration/docker_compose/configuration.rb