Class: AuditEvent
Constant Summary
collapse
- PARALLEL_PERSISTENCE_COLUMNS =
[
:author_name,
:entity_path,
:target_details,
:target_type,
:target_id
].freeze
BulkInsertSafe::ALLOWED_CALLBACKS, BulkInsertSafe::DEFAULT_BATCH_SIZE, BulkInsertSafe::MethodNotAllowedError, BulkInsertSafe::PrimaryKeySetError
ApplicationRecord::MAX_PLUCK
ResetOnUnionError::MAX_RESET_PERIOD
Class Method Summary
collapse
Instance Method Summary
collapse
#run_after_commit, #run_after_commit_or_now
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#serializable_hash
Class Method Details
.order_by(method) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'app/models/audit_event.rb', line 48
def self.order_by(method)
case method.to_s
when 'created_asc'
order(id: :asc)
else
order(id: :desc)
end
end
|
Instance Method Details
#as_json(options = {}) ⇒ Object
85
86
87
88
89
|
# File 'app/models/audit_event.rb', line 85
def as_json(options = {})
super(options).tap do |json|
json['ip_address'] = ip_address.to_s
end
end
|
#author ⇒ Object
73
74
75
|
# File 'app/models/audit_event.rb', line 73
def author
lazy_author&.itself.presence || default_author_value
end
|
#author_name ⇒ Object
63
64
65
|
# File 'app/models/audit_event.rb', line 63
def author_name
author&.name
end
|
67
68
69
70
71
|
# File 'app/models/audit_event.rb', line 67
def formatted_details
details
.merge(details.slice(:from, :to).transform_values(&:to_s))
.merge(author_email: author.try(:email))
end
|
#initialize_details ⇒ Object
57
58
59
60
61
|
# File 'app/models/audit_event.rb', line 57
def initialize_details
return unless has_attribute?(:details)
self.details = {} if details&.nil?
end
|
#lazy_author ⇒ Object
77
78
79
80
81
82
83
|
# File 'app/models/audit_event.rb', line 77
def lazy_author
BatchLoader.for(author_id).batch do |author_ids, loader|
User.select(:id, :name, :username, :email).where(id: author_ids).find_each do |user|
loader.call(user.id, user)
end
end
end
|
#target_details ⇒ Object
99
100
101
|
# File 'app/models/audit_event.rb', line 99
def target_details
super || details[:target_details]
end
|
#target_id ⇒ Object
95
96
97
|
# File 'app/models/audit_event.rb', line 95
def target_id
details[:target_id]
end
|
#target_type ⇒ Object
91
92
93
|
# File 'app/models/audit_event.rb', line 91
def target_type
super || details[:target_type]
end
|