# frozen_string_literal: true class Session < ApplicationRecord ################ # Associations # ################ belongs_to :account ############# # Callbacks # ############# before_validation :turn_nils_into_blanks before_validation :strip_extra_spaces ############### # Validations # ############### validates :logged_at, presence: true validates :ip_address, presence: true validates :user_agent, length: { maximum: 10_000 } private def turn_nils_into_blanks self.user_agent = '' if user_agent.blank? end def strip_extra_spaces self.user_agent = user_agent&.strip end end