Module: Janus::Hooks::ClassMethods

Defined in:
lib/janus/hooks.rb

Overview

Hooks allow you the react at the different steps of a user session. All callbacks will receive the same arguments: user, manager and options.

Example:

Janus::Manager. do |user, manager, options|
  session = manager.session(options[:scope])

  # write some great code here
end

Options:

  • :scope

Instance Method Summary collapse

Instance Method Details

#after_authenticate(&block) ⇒ Object

Executed after a strategy succeeds to authenticate a user.



23
24
25
# File 'lib/janus/hooks.rb', line 23

def after_authenticate(&block)
  add_callback(:authenticate, block)
end

#after_fetch(&block) ⇒ Object

Executed the first time an authenticated user is fetched from session.



28
29
30
# File 'lib/janus/hooks.rb', line 28

def after_fetch(&block)
  add_callback(:fetch, block)
end

#after_login(&block) ⇒ Object

Executed after a user is logged in.



33
34
35
# File 'lib/janus/hooks.rb', line 33

def (&block)
  add_callback(:login, block)
end

#after_logout(&block) ⇒ Object

Executed after a user is logged out. after_logout will be executed for each scope when logging out from multiple scopes at once.



39
40
41
# File 'lib/janus/hooks.rb', line 39

def after_logout(&block)
  add_callback(:logout, block)
end

#run_callbacks(kind, *args) ⇒ Object

:nodoc:



43
44
45
# File 'lib/janus/hooks.rb', line 43

def run_callbacks(kind, *args) # :nodoc:
  callbacks(kind).each { |block| block.call(*args) }
end