Class: IronAdmin::AuditLog::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/iron_admin/audit_log.rb

Overview

Represents a single audit log entry.

Contains details about who performed what action on which record.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Entry

Creates a new audit entry.

Parameters:

  • attrs (Hash) (defaults to: {})

    Entry attributes

Options Hash (attrs):

  • :user (Object)

    The user who performed the action

  • :action (Symbol)

    The action type

  • :resource (String)

    The resource name

  • :record_id (Integer, String)

    The record ID

  • :changes (Hash)

    The attribute changes

  • :ip_address (String)

    The request IP

  • :timestamp (Time)

    When it occurred (defaults to now)



72
73
74
75
# File 'lib/iron_admin/audit_log.rb', line 72

def initialize(attrs = {})
  attrs.each { |k, v| send("#{k}=", v) }
  @timestamp ||= Time.current
end

Instance Attribute Details

#actionSymbol

Returns The action type (:create, :update, :delete).

Returns:

  • (Symbol)

    The action type (:create, :update, :delete)



45
46
47
# File 'lib/iron_admin/audit_log.rb', line 45

def action
  @action
end

#changesHash

Returns The attribute changes (for updates).

Returns:

  • (Hash)

    The attribute changes (for updates)



54
55
56
# File 'lib/iron_admin/audit_log.rb', line 54

def changes
  @changes
end

#ip_addressString

Returns The IP address of the request.

Returns:

  • (String)

    The IP address of the request



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

def ip_address
  @ip_address
end

#record_idInteger, String

Returns The ID of the affected record.

Returns:

  • (Integer, String)

    The ID of the affected record



51
52
53
# File 'lib/iron_admin/audit_log.rb', line 51

def record_id
  @record_id
end

#resourceString

Returns The resource name (e.g., "users").

Returns:

  • (String)

    The resource name (e.g., "users")



48
49
50
# File 'lib/iron_admin/audit_log.rb', line 48

def resource
  @resource
end

#timestampTime

Returns When the action occurred.

Returns:

  • (Time)

    When the action occurred



60
61
62
# File 'lib/iron_admin/audit_log.rb', line 60

def timestamp
  @timestamp
end

#userObject

Returns The user who performed the action.

Returns:

  • (Object)

    The user who performed the action



42
43
44
# File 'lib/iron_admin/audit_log.rb', line 42

def user
  @user
end

Instance Method Details

#to_hHash

Converts the entry to a hash.

Returns:

  • (Hash)

    Entry attributes as a hash



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/iron_admin/audit_log.rb', line 80

def to_h
  {
    user: user,
    action: action,
    resource: resource,
    record_id: record_id,
    changes: changes,
    ip_address: ip_address,
    timestamp: timestamp,
  }
end