class AutoForme::Frameworks::Roda::Request

Public Class Methods

new(roda, path) click to toggle 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) click to toggle source

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

   # 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     # :nocov:
57     token = if @controller.use_request_specific_csrf_tokens?
58       @controller.csrf_token(@controller.csrf_path(action))
59     else
60       @controller.csrf_token
61     end
62     {@controller.csrf_field=>token}
63     # :nocov:
64   elsif defined?(::Rack::Csrf)
65     {::Rack::Csrf.field=>::Rack::Csrf.token(@env)}
66   end
67 end
redirect(path) click to toggle source

Redirect to the given path

   # File lib/autoforme/frameworks/roda.rb
31 def redirect(path)
32   @request.redirect(path)
33 end
set_flash_notice(message) click to toggle source

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

   # File lib/autoforme/frameworks/roda.rb
42 def set_flash_notice(message)
43   @controller.flash[flash_symbol_keys? ? :notice : 'notice'] = message
44 end
set_flash_now_error(message) click to toggle source

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

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

Whether the request is an asynchronous request

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

Private Instance Methods

flash_symbol_keys?() click to toggle source
   # File lib/autoforme/frameworks/roda.rb
71 def flash_symbol_keys?
72   !@controller.opts[:sessions_convert_symbols]
73 end