Sha256: 56d96b37827334e52b1adfd4e805a378577d1984494d1c767035aeea58f90827

Contents?: true

Size: 761 Bytes

Versions: 1

Compression:

Stored size: 761 Bytes

Contents

# frozen_string_literal: true

module CurrentSession
  #
  # Implementation of session tokens for DB management
  #
  class ActiveRecordSession < Repository
    def find
      session_token_class.find_by(value: session_token).try do |record|
        update(record)
        yield record.user
      end
    end

    def create(user)
      session_token_class.create(user_id: user.id, value: new_session_token) do |record|
        update(record)
      end.value
    end

    def update(token)
      token.update(
        last_request_at: current_time,
        last_request_ip: request.remote_ip,
        last_request_user_agent: request.user_agent
      )
    end

    def destroy
      session_token_class.find_by(value: session_token)&.destroy
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
current_session-0.1.0 lib/current_session/active_record_session.rb