Class: Auther::Gatekeeper

Inherits:
Object
  • Object
show all
Defined in:
lib/auther/gatekeeper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application, settings = {}) ⇒ Gatekeeper

Returns a new instance of Gatekeeper.



7
8
9
10
# File 'lib/auther/gatekeeper.rb', line 7

def initialize application, settings = {}
  @application = application
  @settings = Auther::Settings.new settings
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



3
4
5
# File 'lib/auther/gatekeeper.rb', line 3

def application
  @application
end

#environmentObject (readonly)

Returns the value of attribute environment.



3
4
5
# File 'lib/auther/gatekeeper.rb', line 3

def environment
  @environment
end

#settingsObject (readonly)

Returns the value of attribute settings.



3
4
5
# File 'lib/auther/gatekeeper.rb', line 3

def settings
  @settings
end

Instance Method Details

#call(environment) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/auther/gatekeeper.rb', line 12

def call environment
  @environment = environment

  if authorized?(request.path)
    application.call environment
  else
    session[Auther::Keymaster.redirect_url_key] = request.path
    denied_response = response
    denied_response.redirect settings.auth_url
    denied_response.finish
  end
end