class Moneta::Adapters::ActiveRecord::Backend

@api private

Attributes

connection_lock[R]
table_name[R]

Public Class Methods

new(table:, connection: nil, **options) click to toggle source
# File lib/moneta/adapters/activerecord/backend.rb, line 17
def initialize(table:, connection: nil, **options)
  @table_name = table
  @connection = connection
  if connection
    @owner_name =
      case connection
      when Symbol, String
        connection.to_s
      when Hash
        hash = connection.reject { |key| [:username, 'username', :password, 'password'].member?(key) }
        'moneta?' + URI.encode_www_form(hash.to_a.sort)
      when nil
        nil
      else
        raise "Unexpected connection: #{connection}"
      end
  end
end

Public Instance Methods

connection_pool() click to toggle source
# File lib/moneta/adapters/activerecord/backend.rb, line 36
def connection_pool
  if @connection
    connection_handler.retrieve_connection_pool(@owner_name) ||
      self.class.connection_lock.synchronize do
        connection_handler.retrieve_connection_pool(@owner_name) ||
          connection_handler.establish_connection(@connection, owner_name: @owner_name)
      end
  else
    ::ActiveRecord::Base.connection_pool
  end
end