Sha256: dcb5205704f4b652a3223df0dba881951208c7d3ebc21ad9d8438682752ed2d0

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Orchestration
  module Services
    module Mongo
      class Configuration
        include ConfigurationBase

        self.service_name = 'mongo'

        def initialize(env, service_name = nil)
          super
          @settings = nil
          return unless defined?(Mongoid)
          return unless File.exist?(@env.mongoid_configuration_path)

          @settings = { clients_key => hosts_config }
        end

        def friendly_config
          "[mongoid] #{host}:#{local_port}/#{database}"
        end

        private

        def hosts_config
          {
            'default' => {
              'hosts' => ["#{host}:#{port}"],
              'database' => database
            }
          }
        end

        def database
          config
            .fetch(@env.environment)
            .fetch(clients_key)
            .fetch('default')
            .fetch('database')
        end

        def port
          DockerCompose::MongoService::PORT
        end

        def clients_key
          return 'clients' if config.fetch(@env.environment).key?('clients')

          # Support older Mongoid versions
          'sessions'
        end

        def config
          @config ||= YAML.safe_load(
            File.read(@env.mongoid_configuration_path), [], [], true
          )
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
orchestration-0.3.4 lib/orchestration/services/mongo/configuration.rb
orchestration-0.3.3 lib/orchestration/services/mongo/configuration.rb
orchestration-0.3.2 lib/orchestration/services/mongo/configuration.rb
orchestration-0.3.1 lib/orchestration/services/mongo/configuration.rb
orchestration-0.3.0 lib/orchestration/services/mongo/configuration.rb
orchestration-0.2.8 lib/orchestration/services/mongo/configuration.rb
orchestration-0.2.7 lib/orchestration/services/mongo/configuration.rb