You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
840 B

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: session_activations
  5. #
  6. # id :integer not null, primary key
  7. # user_id :integer not null
  8. # session_id :string not null
  9. # created_at :datetime not null
  10. # updated_at :datetime not null
  11. #
  12. class SessionActivation < ApplicationRecord
  13. LIMIT = Rails.configuration.x.max_session_activations
  14. def self.active?(id)
  15. id && where(session_id: id).exists?
  16. end
  17. def self.activate(id)
  18. activation = create!(session_id: id)
  19. purge_old
  20. activation
  21. end
  22. def self.deactivate(id)
  23. return unless id
  24. where(session_id: id).destroy_all
  25. end
  26. def self.purge_old
  27. order('created_at desc').offset(LIMIT).destroy_all
  28. end
  29. def self.exclusive(id)
  30. where('session_id != ?', id).destroy_all
  31. end
  32. end