Class: AutoForme::Frameworks::Sinatra::Request

Inherits:
Request
  • Object
show all
Defined in:
lib/autoforme/frameworks/sinatra.rb

Instance Attribute Summary

Attributes inherited from Request

#action_type, #controller, #id, #method, #model, #params, #path, #session

Instance Method Summary collapse

Methods inherited from Request

#post?, #query_string, #set_flash_notice, #set_flash_now_error

Constructor Details

#initialize(controller) ⇒ Request

Returns a new instance of Request.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/autoforme/frameworks/sinatra.rb', line 5

def initialize(controller)
  @controller = controller
  @request = controller.request
  @params = controller.params
  @session = controller.session
  captures = @params[:captures] || []
  @env = @request.env
  @method = @env['REQUEST_METHOD']
  @model = captures[0]
  @action_type = captures[1]
  @path = @env['SCRIPT_NAME']
  @id = @params[:id] || captures[2]
end

Instance Method Details

#csrf_token_hashObject

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



30
31
32
# File 'lib/autoforme/frameworks/sinatra.rb', line 30

def csrf_token_hash
  {::Rack::Csrf.field=>::Rack::Csrf.token(@env)} if defined?(::Rack::Csrf)
end

#redirect(path) ⇒ Object

Redirect to the given path



20
21
22
# File 'lib/autoforme/frameworks/sinatra.rb', line 20

def redirect(path)
  controller.redirect(path)
end

#xhr?Boolean

Whether the request is an asynchronous request

Returns:

  • (Boolean)


25
26
27
# File 'lib/autoforme/frameworks/sinatra.rb', line 25

def xhr?
  @env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i
end