class AutoForme::Frameworks::Roda::Request

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

Methods

Public Class

  1. new

Public Instance

  1. csrf_token_hash
  2. redirect
  3. set_flash_notice
  4. set_flash_now_error
  5. xhr?

Public Class methods

new(roda, path)
[show source]
   # File lib/autoforme/frameworks/roda.rb
 7 def initialize(roda, path)
 8   @controller = roda 
 9   @request = roda.request
10   @params = @request.params
11   @session = roda.session
12   captures = @request.captures
13   @env = @request.env
14   @method = @env['REQUEST_METHOD']
15   @model = captures[-2]
16   @action_type = captures[-1]
17   @path = path
18   remaining_path = if @request.respond_to?(:remaining_path)
19     @request.remaining_path
20   else
21     # :nocov:
22     @env['PATH_INFO']
23     # :nocov:
24   end
25 
26   path_id = $1 if remaining_path =~ %r{\A\/([:\w-]+)\z}
27   set_id(path_id)
28 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/roda.rb
53 def csrf_token_hash(action=nil)
54   if @controller.respond_to?(:check_csrf!)
55     # Using route_csrf plugin
56     token = if @controller.use_request_specific_csrf_tokens?
57       @controller.csrf_token(@controller.csrf_path(action))
58       # :nocov:
59     else
60       @controller.csrf_token
61       # :nocov:
62     end
63     {@controller.csrf_field=>token}
64     # :nocov:
65   elsif defined?(::Rack::Csrf) && !@controller.opts[:no_csrf]
66     {::Rack::Csrf.field=>::Rack::Csrf.token(@env)}
67     # :nocov:
68   end
69 end
redirect(path)

Redirect to the given path

[show source]
   # File lib/autoforme/frameworks/roda.rb
31 def redirect(path)
32   @request.redirect(path)
33 end
set_flash_notice(message)

Set the flash at notice level when redirecting, so it shows up on the redirected page.

[show source]
   # File lib/autoforme/frameworks/roda.rb
42 def set_flash_notice(message)
43   @controller.flash[flash_key(:notice)] = message
44 end
set_flash_now_error(message)

Set the current flash at error level, used when displaying pages when there is an error.

[show source]
   # File lib/autoforme/frameworks/roda.rb
48 def set_flash_now_error(message)
49   @controller.flash.now[flash_key(:error)] = message
50 end
xhr?()

Whether the request is an asynchronous request

[show source]
   # File lib/autoforme/frameworks/roda.rb
36 def xhr?
37   @env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i
38 end