Class: Rack::OAuth2::Server::Admin::Mount

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/oauth2/server/admin.rb

Overview

Rack module that mounts the specified class on the specified path, and passes all other request to the application.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Mount

Returns a new instance of Mount.



26
27
28
29
# File 'lib/rack/oauth2/server/admin.rb', line 26

def initialize(app)
  @pass = app
  @admin = self.class.klass.new
end

Class Attribute Details

.klassObject (readonly)

Returns the value of attribute klass.



23
24
25
# File 'lib/rack/oauth2/server/admin.rb', line 23

def klass
  @klass
end

.matchObject (readonly)

Returns the value of attribute match.



23
24
25
# File 'lib/rack/oauth2/server/admin.rb', line 23

def match
  @match
end

.pathObject (readonly)

Returns the value of attribute path.



23
24
25
# File 'lib/rack/oauth2/server/admin.rb', line 23

def path
  @path
end

Class Method Details

.mount(klass, path) ⇒ Object



17
18
19
20
21
# File 'lib/rack/oauth2/server/admin.rb', line 17

def mount(klass, path)
  @klass = klass
  @path = path
  @match = /^#{Regexp.escape(path)}(\/.*|$)?/
end

Instance Method Details

#call(env) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/rack/oauth2/server/admin.rb', line 31

def call(env)
  path = env["PATH_INFO"].to_s
  script_name = env['SCRIPT_NAME']
  if path =~ self.class.match && rest = $1
    env.merge! "SCRIPT_NAME"=>(script_name + self.class.path), "PATH_INFO"=>rest
    return @admin.call(env)
  else
    return @pass.call(env)
  end
end