Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_audit_log/extensions/postgresql_adapter.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#blank_audit_user_id_and_nameObject



53
54
55
56
# 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) ⇒ Object



13
14
15
16
17
18
19
20
21
# 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) ⇒ Object



5
6
7
8
9
10
# 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_query_with_pg_audit_log(sql, name = 'SQL', binds = []) ⇒ Object



71
72
73
74
75
# File 'lib/pg_audit_log/extensions/postgresql_adapter.rb', line 71

def exec_query_with_pg_audit_log(sql, name = 'SQL', binds = [])
  conn = exec_query_without_pg_audit_log(sql, name, binds)
  set_audit_user_id_and_name
  conn
end

#execute_with_pg_audit_log(sql, name = nil) ⇒ Object



64
65
66
67
68
# File 'lib/pg_audit_log/extensions/postgresql_adapter.rb', line 64

def execute_with_pg_audit_log(sql, name = nil)
  conn = execute_without_pg_audit_log(sql, name = nil)
  set_audit_user_id_and_name
  conn
end

#reconnect_with_pg_audit_log!Object



58
59
60
61
# 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) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# 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_nameObject



37
38
39
40
41
42
43
44
45
46
47
# 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) ⇒ Object



49
50
51
# 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