Class: ActionDispatch::Routing::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/foyer/rails.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(guard = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/foyer/rails.rb', line 5

def authenticate(guard=nil)
  constraint = lambda do |request|
    if user_id = request.env['rack.session'][Foyer.session_key].try(:[], :id)
      guard.nil?? true : guard.call(Foyer.user_finder.call(user_id))
    end
  end

  constraints(constraint) do
    yield
  end
end