Class: AuditTables::ChangeAuditTable

Inherits:
Base
  • Object
show all
Defined in:
lib/audit_tables/change_audit_table.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#audit_table_name, #column, #klass, #table_name

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from AuditTables::Base

Instance Attribute Details

#audit_columnObject

Returns the value of attribute audit_column.



4
5
6
# File 'lib/audit_tables/change_audit_table.rb', line 4

def audit_column
  @audit_column
end

Instance Method Details

#audit_changesObject



6
7
8
9
10
11
12
# File 'lib/audit_tables/change_audit_table.rb', line 6

def audit_changes
  columns(audit_table_name).each do |audit_column|
    @audit_column = audit_column

    column_exists?(table_name, audit_column.name) ? change_attribute : remove_attribute
  end
end

#change_attributeObject



14
15
16
# File 'lib/audit_tables/change_audit_table.rb', line 14

def change_attribute
  change_column audit_table_name, column_name, column_type, properties_curator if properties_curator.count.positive?
end

#executeObject



18
19
20
21
# File 'lib/audit_tables/change_audit_table.rb', line 18

def execute
  audit_columns
  audit_changes
end

#find_column(column) ⇒ Object



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

def find_column(column)
  columns(table_name).each { |col| @column = col if column.name == col.name }
end

#properties_curatorObject

rubocop:disable Metrics/AbcSize:



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/audit_tables/change_audit_table.rb', line 28

def properties_curator
  elements = {}
  find_column(audit_column)

  elements[:limit] = limit unless audit_column.limit == limit
  elements[:precision] = precision unless audit_column.precision == precision
  elements[:scale] = scale unless audit_column.scale == scale
  elements[:null] = null unless audit_column.null == null
  elements[:default] = default unless audit_column.default == default

  elements
end

#remove_attributeObject

rubocop:enable Metrics/AbcSize:



42
43
44
# File 'lib/audit_tables/change_audit_table.rb', line 42

def remove_attribute
  remove_column audit_table_name, audit_column.name unless audit_column.name.include? 'audit'
end