Class: Rampart::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/rampart/proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(strategy_manager, session, user_store) ⇒ Proxy

Returns a new instance of Proxy.



3
4
5
6
7
# File 'lib/rampart/proxy.rb', line 3

def initialize(strategy_manager, session, user_store)
  @strategy_manager = strategy_manager
  @session = session
  @user_store = user_store
end

Instance Method Details

#authenticate(*names) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/rampart/proxy.rb', line 19

def authenticate(*names)
  event = @strategy_manager.authenticate!(*names)
  if event.success?
    set_user(event.user)
    event.user
  else
    nil
  end
end

#authenticate!(*names) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/rampart/proxy.rb', line 9

def authenticate!(*names)
  event = @strategy_manager.authenticate!(*names)
  if event.success?
    set_user(event.user)
    event.user
  else
    throw(:rampart, event.to_truple)
  end
end

#logoutObject



29
30
31
# File 'lib/rampart/proxy.rb', line 29

def logout
  @session.delete
end

#set_user(user) ⇒ Object



37
38
39
# File 'lib/rampart/proxy.rb', line 37

def set_user(user)
  @user_store.store(user)
end

#user_idObject



33
34
35
# File 'lib/rampart/proxy.rb', line 33

def user_id
  @session.fetch
end