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



6
7
8
# File 'app/models/journaled/audit_log/event.rb', line 6

def database_operation
  @database_operation
end

#enqueue_optsObject

Returns the value of attribute enqueue_opts

Returns:

  • (Object)

    the current value of enqueue_opts



6
7
8
# File 'app/models/journaled/audit_log/event.rb', line 6

def enqueue_opts
  @enqueue_opts
end

#recordObject

Returns the value of attribute record

Returns:

  • (Object)

    the current value of record



6
7
8
# File 'app/models/journaled/audit_log/event.rb', line 6

def record
  @record
end

#unfiltered_changesObject

Returns the value of attribute unfiltered_changes

Returns:

  • (Object)

    the current value of unfiltered_changes



6
7
8
# File 'app/models/journaled/audit_log/event.rb', line 6

def unfiltered_changes
  @unfiltered_changes
end

Instance Method Details

#actorObject



65
66
67
# File 'app/models/journaled/audit_log/event.rb', line 65

def actor
  Journaled.actor_uri
end

#changesObject



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

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



41
42
43
# File 'app/models/journaled/audit_log/event.rb', line 41

def class_name
  record.class.name
end

#created_atObject



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

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



16
17
18
# File 'app/models/journaled/audit_log/event.rb', line 16

def journaled_enqueue_opts
  record.class.audit_log_config.enqueue_opts
end

#journaled_stream_nameObject



12
13
14
# File 'app/models/journaled/audit_log/event.rb', line 12

def journaled_stream_name
  AuditLog.default_stream_name || super
end

#record_created_atObject



33
34
35
# File 'app/models/journaled/audit_log/event.rb', line 33

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

#record_idObject



49
50
51
# File 'app/models/journaled/audit_log/event.rb', line 49

def record_id
  record.id
end

#record_updated_atObject



37
38
39
# File 'app/models/journaled/audit_log/event.rb', line 37

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

#snapshotObject



60
61
62
63
# File 'app/models/journaled/audit_log/event.rb', line 60

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

#table_nameObject



45
46
47
# File 'app/models/journaled/audit_log/event.rb', line 45

def table_name
  record.class.table_name
end