Completed
Push — master ( 8ffdab...d9364e )
by
unknown
11s
created

ApplicationController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A logged_in? 0 3 1
A verify_session() 0 6 2
A current_participant() 0 3 1
A current_participant_session() 0 4 2
A event_schedule_cache_key() 0 9 1
1
# Filters added to this controller apply to all controllers in the application.
2
# Likewise, all the methods added will be available for all controllers.
3
4
class ApplicationController < ActionController::Base
5
  helper :all # include all helpers, all the time
6
  helper :layout
7
  helper_method :current_participant
8
  helper_method :logged_in?
9
  protect_from_forgery # See ActionController::RequestForgeryProtection for details
10
11
  def current_participant
12
    @current_participant ||= (current_participant_session && current_participant_session.participant)
13
  end
14
  alias_method :current_user, :current_participant
15
16
  def current_participant_session
17
    return @current_participant_session if defined?(@current_participant_session)
18
    @current_participant_session = ParticipantSession.find
19
  end
20
21
  def logged_in?
22
    current_participant_session.present?
23
  end
24
25
  def verify_session
26
    unless logged_in?
27
      flash[:notice] = 'You must be logged in to do that. Please log in or create a new account and try again.'
28
      redirect_to new_login_path
29
    end
30
  end
31
32
  def event_schedule_cache_key(event)
33
    [
34
      event,
35
      event.sessions,
36
      event.participants,
37
      event.timeslots,
38
      event.rooms
39
    ]
40
  end
41
  helper_method :event_schedule_cache_key
42
end
43