Class: Rack::Staging

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-staging.rb,
lib/rack-staging/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Staging

Returns a new instance of Staging.



10
11
12
13
# File 'lib/rack-staging.rb', line 10

def initialize(app, options = {})
  @app = app
  @options = options
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rack-staging.rb', line 15

def call(env)
  request = Rack::Request.new(env)
  
  # Check code in session and return Rails call if is valid
  return @app.call(env) if already_auth?(request)
  
  # If post method check :code_param value
  if request.post? and code_valid?(request.params["staging_code"])
    request.session[:staging_code] = request.params["staging_code"]
    [301, {'Location' => '/'}, ''] # Redirect if code is valid
  else
    render_staging
  end
end