module JamRuby
  class CrashDump < ActiveRecord::Base

    self.table_name = "crash_dumps"

    self.primary_key = 'id'

    belongs_to :user, :inverse_of => :crash_dumps, :class_name => "JamRuby::User"
    
    validates :client_type, presence: true
    validates :client_version, presence: true

    attr_accessor :user_email

    before_validation(:on => :create) do
      self.created_at ||= Time.now
      self.id = SecureRandom.uuid
      self.uri = "dump/#{self.id}-#{self.created_at.to_i}"
    end
    
    def user_email 
      nil if user_id.nil?
      self.user.email
    end

  end
end
