# frozen_string_literal: true
module ESM
class LogEntry < ApplicationRecord
# =============================================================================
# INITIALIZE
# =============================================================================
# =============================================================================
# DATA STRUCTURE
# =============================================================================
attribute :public_id, :uuid
attribute :log_id, :integer
attribute :file_name, :string
attribute :entries, :json
# V1
attribute :log_date, :datetime, default: nil
# =============================================================================
# ASSOCIATIONS
# =============================================================================
belongs_to :log
# =============================================================================
# VALIDATIONS
# =============================================================================
# =============================================================================
# CALLBACKS
# =============================================================================
before_create :generate_uuid
# =============================================================================
# SCOPES
# =============================================================================
# =============================================================================
# CLASS METHODS
# =============================================================================
# =============================================================================
# INSTANCE METHODS
# =============================================================================
def file_date
time = entries.first&.fetch("timestamp")
return if time.blank?
Time.parse(time)
end
private
def generate_uuid
self.public_id = SecureRandom.uuid
end
end
end