Module: AuditTables

Defined in:
lib/audit_tables.rb,
lib/audit_tables/base.rb,
lib/audit_tables/version.rb,
lib/audit_tables/change_audit_table.rb,
lib/audit_tables/build_audit_trigger.rb,
lib/audit_tables/create_new_audit_table.rb,
lib/audit_tables/create_audit_tables_for_existing_tables.rb

Defined Under Namespace

Classes: Base, BuildAuditTrigger, ChangeAuditTable, Configuration, CreateAuditTablesForExistingTables, CreateNewAuditTable

Constant Summary collapse

VERSION =
'1.0.2'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



12
13
14
# File 'lib/audit_tables.rb', line 12

def configuration
  @configuration
end

Class Method Details

.all_audit_tablesObject



32
33
34
35
36
37
# File 'lib/audit_tables.rb', line 32

def self.all_audit_tables
  tables = ActiveRecord::Base.connection.tables
  tables -= config.exclude_tables

  tables
end

.build_audit_triggers_for(table_name) ⇒ Object



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

def self.build_audit_triggers_for(table_name)
  AuditTables::BuildAuditTrigger.new(table_name.to_s).build
end

.change_audit_table_for(table_name) ⇒ Object



61
62
63
# File 'lib/audit_tables.rb', line 61

def self.change_audit_table_for(table_name)
  AuditTables::ChangeAuditTable.new(table_name.to_s).execute
end

.check_for_audit_tablesObject



43
44
45
46
47
48
49
50
51
# File 'lib/audit_tables.rb', line 43

def self.check_for_audit_tables
  messages = []

  all_audit_tables.reject { |table| table.starts_with?('audit_') }.each do |table_name|
    messages << table_name unless all_audit_tables.include? "audit_#{table_name}"
  end

  messages
end

.configObject



23
24
25
# File 'lib/audit_tables.rb', line 23

def self.config
  self.configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



27
28
29
30
# File 'lib/audit_tables.rb', line 27

def self.configure
  self.configuration ||= Configuration.new
  yield(configuration)
end

.create_audit_table_for(table_name) ⇒ Object



53
54
55
# File 'lib/audit_tables.rb', line 53

def self.create_audit_table_for(table_name)
  AuditTables::CreateNewAuditTable.new(table_name.to_s).build
end

.create_audit_tables_for_existing_tablesObject



57
58
59
# File 'lib/audit_tables.rb', line 57

def self.create_audit_tables_for_existing_tables
  AuditTables::CreateAuditTablesForExistingTables.new(config.exclude_tables).process
end

.rebuild_all_audit_triggersObject



65
66
67
68
69
# File 'lib/audit_tables.rb', line 65

def self.rebuild_all_audit_triggers
  all_audit_tables.reject { |table| table.starts_with?('audit_') }.each do |table_name|
    build_audit_triggers_for(table_name)
  end
end