Sha256: 4b9757288be3fe0a2a9fd829185b715097c3fa4a1f12066e2f95b0cefbac3eb2

Contents?: true

Size: 808 Bytes

Versions: 4

Compression:

Stored size: 808 Bytes

Contents

# frozen_string_literal: true
require 'active_support'
require 'active_support/core_ext'

module FreshConnection
  class ConnectionSpecification
    def initialize(spec_name, modify_spec: nil)
      @spec_name = spec_name.to_s
      @modify_spec = modify_spec.with_indifferent_access if modify_spec
    end

    private

    def build_config
      config = base_config.with_indifferent_access

      s_config = replica_config(config)
      config = config.merge(s_config) if s_config

      config = config.merge(@modify_spec) if defined?(@modify_spec)

      config
    end

    def replica_config(config)
      if database_group_url
        config_from_url
      else
        config[@spec_name]
      end
    end

    def database_group_url
      ENV["DATABASE_#{@spec_name.upcase}_URL"]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fresh_connection-3.1.3 lib/fresh_connection/connection_specification.rb
fresh_connection-3.1.2 lib/fresh_connection/connection_specification.rb
fresh_connection-3.1.1 lib/fresh_connection/connection_specification.rb
fresh_connection-3.1.1.rc1 lib/fresh_connection/connection_specification.rb