<commit_before>require "active_record"

module Authem
  class Session < ::ActiveRecord::Base
    self.table_name = :authem_sessions

    belongs_to :subject, polymorphic: true
    scope :by_subject, ->(model){ where(subject_type: model.class.name, subject_id: model.id) }
    scope :active, ->{ where(arel_table[:expires_at].gteq(Time.zone.now)) }
    scope :expired, ->{ where(arel_table[:expires_at].lt(Time.zone.now)) }

    before_create do
      self.token ||= SecureRandom.hex(40)
      self.ttl ||= 30.days
      self.expires_at ||= ttl_from_now
    end

    def refresh
      self.expires_at = ttl_from_now
      save!
    end<commit_msg>Define class methods instead of scopes<commit_after>require "active_record"

module Authem
  class Session < ::ActiveRecord::Base
    self.table_name = :authem_sessions

    belongs_to :subject, polymorphic: true

    before_create do
      self.token ||= SecureRandom.hex(40)
      self.ttl ||= 30.days
      self.expires_at ||= ttl_from_now
    end

    class << self
      def by_subject(record)
        where(subject_type: record.class.name, subject_id: record.id)
      end

      def active
        where(arel_table[:expires_at].gteq(Time.zone.now))
      end

      def expired
        where(arel_table[:expires_at].lt(Time.zone.now))
      end
    end

    def refresh
      self.expires_at = ttl_from_now
      save!
    end
{'fraction_non_alphanumeric': 0.10877447425670776, 'fraction_numerical': 0.005801305293691081, 'mean_word_length': 2.9769452449567724, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7352315', 'n_tokens_mistral': 484, 'n_tokens_neox': 460, 'n_words': 91}