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, #env, #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.



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

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']
  set_id(captures[2])
end

Instance Method Details

#csrf_token_hash(action = nil) ⇒ Object

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



32
33
34
# File 'lib/autoforme/frameworks/sinatra.rb', line 32

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

#redirect(path) ⇒ Object

Redirect to the given path



22
23
24
# File 'lib/autoforme/frameworks/sinatra.rb', line 22

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

#xhr?Boolean

Whether the request is an asynchronous request

Returns:

  • (Boolean)


27
28
29
# File 'lib/autoforme/frameworks/sinatra.rb', line 27

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