Class: Rack::ScreenDoor

Inherits:
Object
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/rack/screen_door.rb,
lib/rack/screen_door/version.rb

Overview

Rack middleware class for simple question and answer authorization.

Constant Summary collapse

'_rack_screen_door'
{ :path => '/', :httponly => true }
DEFAULT_EXPIRES =

1 month

60 * 60 * 24 * 30
DEFAULT_TEMPLATE_PATH =
::File.expand_path('../../../default_template.html.erb', __FILE__)
DEFAULT_SALT =
'SaltySalt'
VERSION =
"0.0.4"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, answer, options = {}) ⇒ ScreenDoor

Creates the middleware.

Parameters:

  • app (Application)

    application

  • answer (String)

    secret answer

  • options (Hash) (defaults to: {})

    options

Options Hash (options):

  • :salt (String) — default: DEFAULT_SALT

    a server-side secret

  • :template_path (String) — default: DEFAULT_TEMPLATE_PATH

    the path to an HTML or ERB file to render

  • :cookie_key (String) — default: DEFAULT_COOKIE_KEY

    the cookie key (name)

  • :cookie_hash (Hash) — default: DEFAULT_COOKIE_HASH

    cookie options that will be passed to Rack::Response#set_cookie

  • :expires (Integer) — default: DEFAULT_EXPIRES

    how long a cookie will persist

  • :bypass_if (Proc)

    a block that gets passed request; truthy return values will be allowed even without a cookie.



35
36
37
38
39
40
41
42
43
44
# File 'lib/rack/screen_door.rb', line 35

def initialize(app, answer, options = {})
  @app           = app
  @answer        = answer
  @salt          = options[:salt]          || DEFAULT_SALT
  @template_path = options[:template_path] || DEFAULT_TEMPLATE_PATH
  @cookie_key    = options[:cookie_key]    || DEFAULT_COOKIE_KEY
  @cookie_hash   = DEFAULT_COOKIE_HASH.merge(options[:cookie_hash] || {})
  @expires       = options[:expires]       || DEFAULT_EXPIRES
  @bypass_if     = options[:bypass_if]
end

Instance Attribute Details

#answerObject (readonly)

Returns the value of attribute answer.



18
19
20
# File 'lib/rack/screen_door.rb', line 18

def answer
  @answer
end

#appObject (readonly)

Returns the value of attribute app.



17
18
19
# File 'lib/rack/screen_door.rb', line 17

def app
  @app
end

#bypass_ifObject (readonly)

Returns the value of attribute bypass_if.



18
19
20
# File 'lib/rack/screen_door.rb', line 18

def bypass_if
  @bypass_if
end

Returns the value of attribute cookie_hash.



17
18
19
# File 'lib/rack/screen_door.rb', line 17

def cookie_hash
  @cookie_hash
end

Returns the value of attribute cookie_key.



17
18
19
# File 'lib/rack/screen_door.rb', line 17

def cookie_key
  @cookie_key
end

#errorObject (readonly)

Returns the value of attribute error.



19
20
21
# File 'lib/rack/screen_door.rb', line 19

def error
  @error
end

#expiresObject (readonly)

Returns the value of attribute expires.



17
18
19
# File 'lib/rack/screen_door.rb', line 17

def expires
  @expires
end

#redirect_urlObject (readonly)

Returns the value of attribute redirect_url.



19
20
21
# File 'lib/rack/screen_door.rb', line 19

def redirect_url
  @redirect_url
end

#saltObject (readonly)

Returns the value of attribute salt.



18
19
20
# File 'lib/rack/screen_door.rb', line 18

def salt
  @salt
end

#template_pathObject (readonly)

Returns the value of attribute template_path.



18
19
20
# File 'lib/rack/screen_door.rb', line 18

def template_path
  @template_path
end

Instance Method Details

#call(env) ⇒ Object

Rack middleware chain.



47
48
49
# File 'lib/rack/screen_door.rb', line 47

def call(env)
  dup._call(env) # make threadsafe
end