Class: Moneta::Adapters::ActiveRecord::Backend Private

Inherits:
Object
  • Object
show all
Defined in:
lib/moneta/adapters/activerecord/backend.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table:, connection: nil, **options) ⇒ Backend

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Backend.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

Class Attribute Details

.connection_lockObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



11
12
13
# File 'lib/moneta/adapters/activerecord/backend.rb', line 11

def connection_lock
  @connection_lock
end

Instance Attribute Details

#table_nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
# File 'lib/moneta/adapters/activerecord/backend.rb', line 14

def table_name
  @table_name
end

Instance Method Details

#connection_poolObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
39
40
41
42
43
44
45
46
# 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