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
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
ResetOnColumnErrors::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, nullable_column?, 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
#reset_on_union_error, #reset_on_unknown_attribute_error
#serializable_hash
Class Method Details
.order_by(method) ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'app/models/audit_event.rb', line 52
def self.order_by(method)
case method.to_s
when 'created_asc'
order(id: :asc)
else
order(id: :desc)
end
end
|
.supported_keyset_orderings ⇒ Object
48
49
50
|
# File 'app/models/audit_event.rb', line 48
def self.supported_keyset_orderings
{ id: [:desc] }
end
|
Instance Method Details
#as_json(options = {}) ⇒ Object
89
90
91
92
93
|
# File 'app/models/audit_event.rb', line 89
def as_json(options = {})
super(options).tap do |json|
json['ip_address'] = ip_address.to_s
end
end
|
#author ⇒ Object
77
78
79
|
# File 'app/models/audit_event.rb', line 77
def author
lazy_author&.itself.presence || default_author_value
end
|
#author_name ⇒ Object
67
68
69
|
# File 'app/models/audit_event.rb', line 67
def author_name
author&.name
end
|
71
72
73
74
75
|
# File 'app/models/audit_event.rb', line 71
def formatted_details
details
.merge(details.slice(:from, :to).transform_values(&:to_s))
.merge(author_email: author.try(:email))
end
|
#initialize_details ⇒ Object
61
62
63
64
65
|
# File 'app/models/audit_event.rb', line 61
def initialize_details
return unless has_attribute?(:details)
self.details = {} if details&.nil?
end
|
#lazy_author ⇒ Object
81
82
83
84
85
86
87
|
# File 'app/models/audit_event.rb', line 81
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
103
104
105
|
# File 'app/models/audit_event.rb', line 103
def target_details
super || details[:target_details]
end
|
#target_id ⇒ Object
99
100
101
|
# File 'app/models/audit_event.rb', line 99
def target_id
details[:target_id]
end
|
#target_type ⇒ Object
95
96
97
|
# File 'app/models/audit_event.rb', line 95
def target_type
super || details[:target_type]
end
|