Class: RailsMultisite::ConnectionManagement::ConnectionSpecification

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_multisite/connection_management/rails_60_compat.rb,
lib/rails_multisite/connection_management/rails_61_compat.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ ConnectionSpecification

Returns a new instance of ConnectionSpecification.



23
24
25
# File 'lib/rails_multisite/connection_management/rails_61_compat.rb', line 23

def initialize(spec)
  @spec = spec
end

Instance Attribute Details

#specObject (readonly)

Returns the value of attribute spec.



21
22
23
# File 'lib/rails_multisite/connection_management/rails_61_compat.rb', line 21

def spec
  @spec
end

Class Method Details

.currentObject



7
8
9
# File 'lib/rails_multisite/connection_management/rails_60_compat.rb', line 7

def current
  ActiveRecord::Base.connection_pool.spec
end

.db_spec_cache(configs) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/rails_multisite/connection_management/rails_60_compat.rb', line 11

def db_spec_cache(configs)
  resolve_configs = configs
  # rails 6 needs to use a proper object for the resolver
  if defined?(ActiveRecord::DatabaseConfigurations)
    resolve_configs = ActiveRecord::DatabaseConfigurations.new(configs)
  end
  resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new(resolve_configs)
  configs.map { |k, _| [k, resolver.spec(k.to_sym)] }.to_h
end

.defaultObject



21
22
23
24
25
# File 'lib/rails_multisite/connection_management/rails_60_compat.rb', line 21

def default
  ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver
    .new(ActiveRecord::Base.configurations)
    .spec(Rails.env.to_sym)
end

Instance Method Details

#nameObject



27
28
29
# File 'lib/rails_multisite/connection_management/rails_61_compat.rb', line 27

def name
  spec.env_name
end

#to_hashObject Also known as: config



31
32
33
# File 'lib/rails_multisite/connection_management/rails_61_compat.rb', line 31

def to_hash
  spec.configuration_hash
end