Sha256: e093d0911bf5c4e5c7252f8c624c7db8e1b760524bcc50c46e7f256983a7230c

Contents?: true

Size: 1.11 KB

Versions: 17

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Orchestration
  module DockerCompose
    class DatabaseService
      include ComposeHelpers

      def initialize(config, environment)
        @environment = environment
        @config = config
      end

      def definition
        return nil unless @config.enabled?
        return nil if adapter.name == 'sqlite3'

        {
          'image' => adapter.image,
          'environment' => adapter.environment
        }.merge(ports).merge(volumes)
      end

      private

      def adapter
        name = ComposeConfiguration.new(@environment).database_adapter_name
        base = 'Orchestration::Services::Database::Adapters'
        Object.const_get("#{base}::#{name.capitalize}").new
      end

      def remote_port
        adapter.default_port
      end

      def ports
        return {} unless %i[development test].include?(@environment)

        { 'ports' => ["#{sidecar_port(@environment)}#{remote_port}"] }
      end

      def volumes
        return {} if @environment == :test

        { 'volumes' => ["#{@config.env.database_volume}:#{adapter.data_dir}"] }
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
orchestration-0.5.6 lib/orchestration/docker_compose/database_service.rb
orchestration-0.5.5 lib/orchestration/docker_compose/database_service.rb
orchestration-0.5.4 lib/orchestration/docker_compose/database_service.rb
orchestration-0.5.3 lib/orchestration/docker_compose/database_service.rb
orchestration-0.5.2 lib/orchestration/docker_compose/database_service.rb
orchestration-0.5.1 lib/orchestration/docker_compose/database_service.rb
orchestration-0.5.0 lib/orchestration/docker_compose/database_service.rb
orchestration-0.4.21 lib/orchestration/docker_compose/database_service.rb
orchestration-0.4.20 lib/orchestration/docker_compose/database_service.rb
orchestration-0.4.19 lib/orchestration/docker_compose/database_service.rb
orchestration-0.4.18 lib/orchestration/docker_compose/database_service.rb
orchestration-0.4.17 lib/orchestration/docker_compose/database_service.rb
orchestration-0.4.16 lib/orchestration/docker_compose/database_service.rb
orchestration-0.4.15 lib/orchestration/docker_compose/database_service.rb
orchestration-0.4.14 lib/orchestration/docker_compose/database_service.rb
orchestration-0.4.13 lib/orchestration/docker_compose/database_service.rb
orchestration-0.4.12 lib/orchestration/docker_compose/database_service.rb