Class: SourceMonitor::Logs::EntrySync
- Inherits:
-
Object
- Object
- SourceMonitor::Logs::EntrySync
- Defined in:
- lib/source_monitor/logs/entry_sync.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(loggable) ⇒ EntrySync
constructor
A new instance of EntrySync.
Constructor Details
#initialize(loggable) ⇒ EntrySync
Returns a new instance of EntrySync.
10 11 12 |
# File 'lib/source_monitor/logs/entry_sync.rb', line 10 def initialize(loggable) @loggable = loggable end |
Class Method Details
.call(loggable) ⇒ Object
6 7 8 |
# File 'lib/source_monitor/logs/entry_sync.rb', line 6 def self.call(loggable) new(loggable).call end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/source_monitor/logs/entry_sync.rb', line 14 def call return unless loggable&.persisted? return unless loggable.respond_to?(:log_entry) entry = loggable.log_entry || loggable.build_log_entry entry.assign_attributes(entry_attributes) entry.save! rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved Rails.logger&.error("[SourceMonitor::Logs::EntrySync] Failed to sync log entry for #{loggable.class.name}##{loggable.id}") nil end |