Class: ActiveRecordProxyAdapters::ActiveRecordContext

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_proxy_adapters/active_record_context.rb

Overview

Collection of helpers to handle common active record methods that are defined in different places in different versions of rails.

Instance Method Summary collapse

Instance Method Details

#active_record_v7?Boolean

rubocop:enable Style/TrailingCommaInArrayLiteral

Returns:

  • (Boolean)


39
40
41
# File 'lib/active_record_proxy_adapters/active_record_context.rb', line 39

def active_record_v7?
  active_record_version >= Gem::Version.new("7.2") && active_record_version < Gem::Version.new("8.0")
end

#active_record_v7_2_or_greater?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/active_record_proxy_adapters/active_record_context.rb', line 43

def active_record_v7_2_or_greater?
  active_record_version >= Gem::Version.new("7.2")
end

#active_record_v8_0_2_or_greater?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/active_record_proxy_adapters/active_record_context.rb', line 51

def active_record_v8_0_2_or_greater?
  active_record_version >= Gem::Version.new("8.0.2")
end

#active_record_v8_0_or_greater?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/active_record_proxy_adapters/active_record_context.rb', line 47

def active_record_v8_0_or_greater?
  active_record_version >= Gem::Version.new("8.0")
end

#connection_class_for(connection) ⇒ Object



14
15
16
17
18
# File 'lib/active_record_proxy_adapters/active_record_context.rb', line 14

def connection_class_for(connection)
  return connection.connection_descriptor.name.constantize if active_record_v8_0_2_or_greater?

  connection.connection_class || ActiveRecord::Base
end

#hijackable_methodsObject

rubocop:disable Style/TrailingCommaInArrayLiteral



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/active_record_proxy_adapters/active_record_context.rb', line 21

def hijackable_methods
  [
    # Create
    :insert,
    :exec_insert_all, # this one is an exception to the rule. there's no higher-level equivalent method to be called
    # Retrieve
    :select,
    # Update
    :update,
    # Delete
    :delete,
    # Generic
    :exec_query,
    :execute,
  ]
end