Sha256: 2c444986eeb382eedbe6474d76065754ea84680eaa2a26627da2ba8bab46131e

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module Orchestration
  module DockerCompose
    class Services
      def initialize(options = {})
        @configurations = {
          'application' => options.fetch(:application, nil),
          'database' => options.fetch(:database, nil),
          'mongo' => options.fetch(:mongo, nil),
          'rabbitmq' => options.fetch(:rabbitmq, nil)
        }
      end

      def structure
        { 'version' => '3.7', 'services' => services }
      end

      def services
        Hash[filtered_services]
      end

      private

      def filtered_services
        services_enabled.compact.reject { |_name, definition| definition.nil? }
      end

      def services_available
        [
          { name: 'application', class: ApplicationService },
          { name: 'database', class: DatabaseService },
          { name: 'mongo', class: MongoService },
          { name: 'rabbitmq', class: RabbitMQService }
        ]
      end

      def services_enabled
        services_available.map do |service|
          config = @configurations[service[:name]]
          # REVIEW: This is mostly here for testing - we may not need it once
          # everything's implemented.
          next if config.nil?

          [service[:name], service[:class].new(config).definition]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
orchestration-0.2.2 lib/orchestration/docker_compose/services.rb