Sha256: 4ac4949fb6886bb4361678fca98cb5f1dfc474af96983a6f818357f2b5b55b30

Contents?: true

Size: 1.99 KB

Versions: 37

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

require 'avm/instances/entry_keys'

module Avm
  module Instances
    class Base
      module AutoValues
        module Database
          DEFAULT_HOSTNAME = '127.0.0.1'
          DEFAULT_LIMIT = 5
          DEFAULT_PORTS = {
            'postgresql' => 5432,
            'mysql' => 3306,
            'oracle' => 1521,
            'sqlserver' => 1433
          }.freeze
          DEFAULT_SYSTEM = 'postgresql'
          DEFAULT_TIMEOUT = 5000

          def auto_database_name
            inherited_entry_value(::Avm::Instances::EntryKeys::DATABASE_ID,
                                  ::Avm::Instances::EntryKeys::DATABASE_NAME) || id
          end

          def auto_database_hostname
            database_auto_common('hostname') || DEFAULT_HOSTNAME
          end

          def auto_database_limit
            database_auto_common('limit') || DEFAULT_LIMIT
          end

          def auto_database_password
            database_auto_common('password')
          end

          def auto_database_port
            database_auto_common('port') || database_port_by_system
          end

          def auto_database_username
            database_auto_common('username')
          end

          def auto_database_system
            database_auto_common('system') || DEFAULT_SYSTEM
          end

          def auto_database_timeout
            database_auto_common('timeout') || DEFAULT_TIMEOUT
          end

          private

          def database_auto_common(suffix)
            database_key = ::Avm::Instances::EntryKeys.const_get("database_#{suffix}".upcase)
            inherited_entry_value(::Avm::Instances::EntryKeys::DATABASE_ID, database_key) ||
              inherited_entry_value(::Avm::Instances::EntryKeys::HOST_ID, database_key)
          end

          def database_port_by_system
            read_entry_optional(::Avm::Instances::EntryKeys::DATABASE_SYSTEM).if_present do |v|
              DEFAULT_PORTS.fetch(v)
            end
          end
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
avm-0.7.0 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.110.0 vendor/avm/lib/avm/instances/base/auto_values/database.rb
avm-tools-0.109.1 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.109.0 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.108.0 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.107.0 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.106.0 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.105.0 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.104.0 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.103.1 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.103.0 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.102.2 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.102.1 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.102.0 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.101.0 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.100.0 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.99.1 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.99.0 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.98.0 lib/avm/instances/base/auto_values/database.rb
avm-tools-0.97.0 lib/avm/instances/base/auto_values/database.rb