class AutoForme::Frameworks::Sinatra::Request

  1. lib/autoforme/frameworks/sinatra.rb
Superclass: Request

Methods

Public Class

  1. new

Public Instance

  1. csrf_token_hash
  2. redirect
  3. xhr?

Public Class methods

new(controller)
[show source]
   # File lib/autoforme/frameworks/sinatra.rb
 7 def initialize(controller)
 8   @controller = controller
 9   @request = controller.request
10   @params = controller.params
11   @session = controller.session
12   captures = @params[:captures] || []
13   @env = @request.env
14   @method = @env['REQUEST_METHOD']
15   @model = captures[0]
16   @action_type = captures[1]
17   @path = @env['SCRIPT_NAME']
18   set_id(captures[2])
19 end

Public Instance methods

csrf_token_hash(action=nil)

Use Rack::Csrf for csrf protection if it is defined.

[show source]
   # File lib/autoforme/frameworks/sinatra.rb
32 def csrf_token_hash(action=nil)
33   # :nocov:
34   if defined?(::Rack::Csrf)
35   # :nocov:
36     {::Rack::Csrf.field=>::Rack::Csrf.token(@env)}
37   end
38 end
redirect(path)

Redirect to the given path

[show source]
   # File lib/autoforme/frameworks/sinatra.rb
22 def redirect(path)
23   controller.redirect(path)
24 end
xhr?()

Whether the request is an asynchronous request

[show source]
   # File lib/autoforme/frameworks/sinatra.rb
27 def xhr?
28   @env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i
29 end