Class: Rack::Staging
- Inherits:
-
Object
- Object
- Rack::Staging
- Defined in:
- lib/staging.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Staging
constructor
A new instance of Staging.
Constructor Details
#initialize(app, options = {}) ⇒ Staging
Returns a new instance of Staging.
9 10 11 12 13 14 15 |
# File 'lib/staging.rb', line 9 def initialize app, = {} @app = app @options = { :session_key => :staging_auth, :code_param => :code }.merge end |
Instance Method Details
#call(env) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/staging.rb', line 17 def call env request = Rack::Request.new env # Check code in session and return Rails call if is valid return @app.call env if \ request.session[@options[:session_key]] != nil and request.session[@options[:session_key]] != '' and code_valid? request.session[@options[:session_key]] # If post method check :code_param value if request.post? and code_valid? request.params[@options[:code_param].to_s] request.session[@options[:session_key]] = request.params[@options[:code_param].to_s] [301, {'Location' => '/'}, ''] # Redirect if code is valid else render_staging end end |