lib/wolf_core/domain/entity.rb
# frozen_string_literal: true module WolfCore class Entity < DomainObject define_attributes :id validates :id, presence: true before_initialize do @id ||= generate_id end def ==(other) id == other.id end def created_at return if id.blank? timestamp = id.split('-')[1].to_i @created_at ||= Time.at(timestamp).utc end private def generate_id prefix = generate_id_prefix timestamp = Time.now.utc.to_i uuid = SecureRandom.uuid.delete('-')[0..9] "#{prefix}-#{timestamp}-#{uuid}" end def generate_id_prefix generate_id_prefix_complete[0..4] end def generate_id_prefix_complete self.class.to_s.underscore.split('/').last.downcase end end end