Wednesday, July 15, 2026 3:59:54 AM
> log_entry.rb
# 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
All opinions represented herein are my own
- © 2024 - 2026 itsthedevman
- build 43aa0d7