Module: DB2Query::ConnectionHandling

Included in:
Base
Defined in:
lib/db2_query/connection_handling.rb

Constant Summary collapse

RAILS_ENV =
-> { (Rails.env if defined?(Rails.env)) || ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence }
DEFAULT_ENV =
-> { RAILS_ENV.call || "default_env" }

Instance Method Summary collapse

Instance Method Details

#connection_specification_nameObject



22
23
24
25
26
27
# File 'lib/db2_query/connection_handling.rb', line 22

def connection_specification_name
  if !defined?(@connection_specification_name) || @connection_specification_name.nil?
    return self == Base ? "primary" : superclass.connection_specification_name
  end
  @connection_specification_name
end

#primary_class?Boolean



29
30
31
# File 'lib/db2_query/connection_handling.rb', line 29

def primary_class?
  self == Base || defined?(ApplicationRecord) && self == ApplicationRecord
end

#resolve_config_for_connection(config_or_env) ⇒ Object

:nodoc:



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/db2_query/connection_handling.rb', line 8

def resolve_config_for_connection(config_or_env) # :nodoc:
  raise "Anonymous class is not allowed." unless name

  config_or_env ||= DEFAULT_ENV.call.to_sym
  pool_name = primary_class? ? "primary" : name
  self.connection_specification_name = pool_name
  resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(Base.configurations)

  config_hash = resolver.resolve(config_or_env, pool_name).symbolize_keys
  config_hash[:name] = pool_name

  config_hash
end