Class: Journaled::AuditLog::Event

Inherits:
Struct
  • Object
show all
Includes:
Event
Defined in:
app/models/journaled/audit_log/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Event

#event_type, #id, #journal!, #journaled_attributes, #journaled_partition_key, #journaled_schema_name, #tagged?

Instance Attribute Details

#database_operationObject

Returns the value of attribute database_operation

Returns:

  • (Object)

    the current value of database_operation



8
9
10
# File 'app/models/journaled/audit_log/event.rb', line 8

def database_operation
  @database_operation
end

#enqueue_optsObject

Returns the value of attribute enqueue_opts

Returns:

  • (Object)

    the current value of enqueue_opts



8
9
10
# File 'app/models/journaled/audit_log/event.rb', line 8

def enqueue_opts
  @enqueue_opts
end

#recordObject

Returns the value of attribute record

Returns:

  • (Object)

    the current value of record



8
9
10
# File 'app/models/journaled/audit_log/event.rb', line 8

def record
  @record
end

#unfiltered_changesObject

Returns the value of attribute unfiltered_changes

Returns:

  • (Object)

    the current value of unfiltered_changes



8
9
10
# File 'app/models/journaled/audit_log/event.rb', line 8

def unfiltered_changes
  @unfiltered_changes
end

Instance Method Details

#actorObject



67
68
69
# File 'app/models/journaled/audit_log/event.rb', line 67

def actor
  Journaled.actor_uri
end

#changesObject



55
56
57
58
59
60
# File 'app/models/journaled/audit_log/event.rb', line 55

def changes
  filtered_changes = unfiltered_changes.deep_dup.deep_symbolize_keys
  filtered_changes.each do |key, value|
    filtered_changes[key] = value.map { |val| '[FILTERED]' if val } if filter_key?(key)
  end
end

#class_nameObject



43
44
45
# File 'app/models/journaled/audit_log/event.rb', line 43

def class_name
  record.class.name
end

#created_atObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/journaled/audit_log/event.rb', line 22

def created_at
  case database_operation
    when 'insert'
      record_created_at
    when 'update'
      record_updated_at
    when 'delete'
      Time.zone.now
    else
      raise "Unhandled database operation type: #{database_operation}"
  end
end

#journaled_enqueue_optsObject



18
19
20
# File 'app/models/journaled/audit_log/event.rb', line 18

def journaled_enqueue_opts
  record.class.audit_log_config.enqueue_opts
end

#journaled_stream_nameObject



14
15
16
# File 'app/models/journaled/audit_log/event.rb', line 14

def journaled_stream_name
  AuditLog.default_stream_name || super
end

#record_created_atObject



35
36
37
# File 'app/models/journaled/audit_log/event.rb', line 35

def record_created_at
  record.try(:created_at) || Time.zone.now
end

#record_idObject



51
52
53
# File 'app/models/journaled/audit_log/event.rb', line 51

def record_id
  record.id
end

#record_updated_atObject



39
40
41
# File 'app/models/journaled/audit_log/event.rb', line 39

def record_updated_at
  record.try(:updated_at) || Time.zone.now
end

#snapshotObject



62
63
64
65
# File 'app/models/journaled/audit_log/event.rb', line 62

def snapshot
  filtered_attributes if record._log_snapshot || AuditLog.snapshots_enabled ||
    (database_operation == 'delete' && AuditLog.snapshot_on_deletion)
end

#table_nameObject



47
48
49
# File 'app/models/journaled/audit_log/event.rb', line 47

def table_name
  record.class.table_name
end