class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter

Did not want to reopen the class but sending an include seemingly is not working.

Public Instance Methods

blank_audit_user_id_and_name() click to toggle source
# File lib/pg_audit_log/extensions/postgresql_adapter.rb, line 53
def blank_audit_user_id_and_name
  @last_user_id = @last_unique_name = nil
  true
end
create_table_with_auditing(table_name, options = {}, &block) click to toggle source
# File lib/pg_audit_log/extensions/postgresql_adapter.rb, line 13
def create_table_with_auditing(table_name, options = {}, &block)
  create_table_without_auditing(table_name, options, &block)
  unless options[:temporary] ||
      PgAuditLog::IGNORED_TABLES.include?(table_name) ||
      PgAuditLog::IGNORED_TABLES.any? { |table| table =~ table_name if table.is_a? Regexp } ||
      PgAuditLog::Triggers.tables_with_triggers.include?(table_name)
    PgAuditLog::Triggers.create_for_table(table_name)
  end
end
drop_table_with_auditing(table_name) click to toggle source
# File lib/pg_audit_log/extensions/postgresql_adapter.rb, line 5
def drop_table_with_auditing(table_name)
  if PgAuditLog::Triggers.tables_with_triggers.include?(table_name)
    PgAuditLog::Triggers.drop_for_table(table_name)
  end
  drop_table_without_auditing(table_name)
end
exec_delete_with_pg_audit_log(*args, &block) click to toggle source
# File lib/pg_audit_log/extensions/postgresql_adapter.rb, line 85
def exec_delete_with_pg_audit_log(*args, &block)
  set_audit_user_id_and_name
  conn = exec_delete_without_pg_audit_log(*args, &block)
  conn
end
exec_query_with_pg_audit_log(*args, &block) click to toggle source
# File lib/pg_audit_log/extensions/postgresql_adapter.rb, line 71
def exec_query_with_pg_audit_log(*args, &block)
  set_audit_user_id_and_name
  conn = exec_query_without_pg_audit_log(*args, &block)
  conn
end
exec_update_with_pg_audit_log(*args, &block) click to toggle source
# File lib/pg_audit_log/extensions/postgresql_adapter.rb, line 78
def exec_update_with_pg_audit_log(*args, &block)
  set_audit_user_id_and_name
  conn = exec_update_without_pg_audit_log(*args, &block)
  conn
end
execute_with_pg_audit_log(sql, name = nil) click to toggle source
# File lib/pg_audit_log/extensions/postgresql_adapter.rb, line 64
def execute_with_pg_audit_log(sql, name = nil)
  set_audit_user_id_and_name
  conn = execute_without_pg_audit_log(sql, name = nil)
  conn
end
reconnect_with_pg_audit_log!() click to toggle source
# File lib/pg_audit_log/extensions/postgresql_adapter.rb, line 58
def reconnect_with_pg_audit_log!
  reconnect_without_pg_audit_log!
  @last_user_id = @last_unique_name = nil
end
rename_table_with_auditing(table_name, new_name) click to toggle source
# File lib/pg_audit_log/extensions/postgresql_adapter.rb, line 24
def rename_table_with_auditing(table_name, new_name)
  if PgAuditLog::Triggers.tables_with_triggers.include?(table_name)
    PgAuditLog::Triggers.drop_for_table(table_name)
  end
  rename_table_without_auditing(table_name, new_name)
  unless PgAuditLog::IGNORED_TABLES.include?(table_name) ||
      PgAuditLog::IGNORED_TABLES.any? { |table| table =~ table_name if table.is_a? Regexp } ||
      PgAuditLog::Triggers.tables_with_triggers.include?(new_name)
    PgAuditLog::Triggers.create_for_table(new_name)
  end
end
set_audit_user_id_and_name() click to toggle source
# File lib/pg_audit_log/extensions/postgresql_adapter.rb, line 37
def set_audit_user_id_and_name
  user_id, unique_name = user_id_and_name
  return true if (@last_user_id && @last_user_id == user_id) && (@last_unique_name && @last_unique_name == unique_name)

  execute_without_pg_audit_log PgAuditLog::Function::user_identifier_temporary_function(user_id)
  execute_without_pg_audit_log PgAuditLog::Function::user_unique_name_temporary_function(unique_name)
  @last_user_id = user_id
  @last_unique_name = unique_name

  true
end
set_user_id(user_id = nil) click to toggle source
# File lib/pg_audit_log/extensions/postgresql_adapter.rb, line 49
def set_user_id(user_id = nil)
  execute_without_pg_audit_log PgAuditLog::Function::user_identifier_temporary_function(user_id || @last_user_id)
end

Private Instance Methods

user_id_and_name() click to toggle source
# File lib/pg_audit_log/extensions/postgresql_adapter.rb, line 94
def user_id_and_name
  current_user = Thread.current[:current_user]
  user_id = current_user.try(:id) || "-1"
  user_unique_name = current_user.try(:unique_name) || "UNKNOWN"
  return [user_id, user_unique_name]
end