module QuizHelperMethods
  extend ActiveSupport::Concern

  included do
    before_action :require_player!
    before_action :set_locale

    helper_method :current_player
  end


private


  def require_player!
    unless player_present?
      redirect_to url_for(controller: "languages", action: "index") and return
    end
  end


  def current_player
    Current.player ||= player_from_session
  end


  def player_from_session
    Player.find_by(id: session[:player_id])
  end


  def player_present?
    current_player.present?
  end
end
