Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- 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
- #blank_audit_user_id_and_name ⇒ Object
- #create_table_with_auditing(table_name, options = {}, &block) ⇒ Object
- #drop_table_with_auditing(table_name) ⇒ Object
- #exec_query_with_pg_audit_log(sql, name = 'SQL', binds = []) ⇒ Object
- #execute_with_pg_audit_log(sql, name = nil) ⇒ Object
- #reconnect_with_pg_audit_log! ⇒ Object
- #rename_table_with_auditing(table_name, new_name) ⇒ Object
- #set_audit_user_id_and_name ⇒ Object
- #set_user_id(user_id = nil) ⇒ Object
Instance Method Details
#blank_audit_user_id_and_name ⇒ Object
50 51 52 53 |
# File 'lib/pg_audit_log/extensions/postgresql_adapter.rb', line 50 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 |
# File 'lib/pg_audit_log/extensions/postgresql_adapter.rb', line 13 def create_table_with_auditing(table_name, = {}, &block) create_table_without_auditing(table_name, , &block) unless [:temporary] || PgAuditLog::IGNORED_TABLES.include?(table_name) || 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
68 69 70 71 72 |
# File 'lib/pg_audit_log/extensions/postgresql_adapter.rb', line 68 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
61 62 63 64 65 |
# File 'lib/pg_audit_log/extensions/postgresql_adapter.rb', line 61 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
55 56 57 58 |
# File 'lib/pg_audit_log/extensions/postgresql_adapter.rb', line 55 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
23 24 25 26 27 28 29 30 31 |
# File 'lib/pg_audit_log/extensions/postgresql_adapter.rb', line 23 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::Triggers.tables_with_triggers.include?(new_name) PgAuditLog::Triggers.create_for_table(new_name) end end |
#set_audit_user_id_and_name ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pg_audit_log/extensions/postgresql_adapter.rb', line 34 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
46 47 48 |
# File 'lib/pg_audit_log/extensions/postgresql_adapter.rb', line 46 def set_user_id(user_id = nil) execute_without_pg_audit_log PgAuditLog::Function::user_identifier_temporary_function(user_id || @last_user_id) end |