Class: AutoForme::Frameworks::Roda::Request
- Defined in:
- lib/autoforme/frameworks/roda.rb
Instance Attribute Summary
Attributes inherited from Request
#action_type, #controller, #env, #id, #method, #model, #params, #path, #session
Instance Method Summary collapse
-
#csrf_token_hash(action = nil) ⇒ Object
Use Rack::Csrf for csrf protection if it is defined.
-
#initialize(roda, path) ⇒ Request
constructor
A new instance of Request.
-
#redirect(path) ⇒ Object
Redirect to the given path.
-
#set_flash_notice(message) ⇒ Object
Set the flash at notice level when redirecting, so it shows up on the redirected page.
-
#set_flash_now_error(message) ⇒ Object
Set the current flash at error level, used when displaying pages when there is an error.
-
#xhr? ⇒ Boolean
Whether the request is an asynchronous request.
Methods inherited from Request
Constructor Details
#initialize(roda, path) ⇒ Request
Returns a new instance of Request.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/autoforme/frameworks/roda.rb', line 7 def initialize(roda, path) @controller = roda @request = roda.request @params = @request.params @session = roda.session captures = @request.captures @env = @request.env @method = @env['REQUEST_METHOD'] @model = captures[-2] @action_type = captures[-1] @path = path remaining_path = if @request.respond_to?(:remaining_path) @request.remaining_path else # :nocov: @env['PATH_INFO'] # :nocov: end path_id = $1 if remaining_path =~ %r{\A\/([\w-]+)\z} set_id(path_id) end |
Instance Method Details
#csrf_token_hash(action = nil) ⇒ Object
Use Rack::Csrf for csrf protection if it is defined.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/autoforme/frameworks/roda.rb', line 53 def csrf_token_hash(action=nil) if @controller.respond_to?(:check_csrf!) # Using route_csrf plugin token = if @controller.use_request_specific_csrf_tokens? @controller.csrf_token(@controller.csrf_path(action)) # :nocov: else @controller.csrf_token # :nocov: end {@controller.csrf_field=>token} # :nocov: elsif defined?(::Rack::Csrf) && !@controller.opts[:no_csrf] {::Rack::Csrf.field=>::Rack::Csrf.token(@env)} # :nocov: end end |
#redirect(path) ⇒ Object
Redirect to the given path
31 32 33 |
# File 'lib/autoforme/frameworks/roda.rb', line 31 def redirect(path) @request.redirect(path) end |
#set_flash_notice(message) ⇒ Object
Set the flash at notice level when redirecting, so it shows up on the redirected page.
42 43 44 |
# File 'lib/autoforme/frameworks/roda.rb', line 42 def set_flash_notice() @controller.flash[flash_key(:notice)] = end |
#set_flash_now_error(message) ⇒ Object
Set the current flash at error level, used when displaying pages when there is an error.
48 49 50 |
# File 'lib/autoforme/frameworks/roda.rb', line 48 def set_flash_now_error() @controller.flash.now[flash_key(:error)] = end |
#xhr? ⇒ Boolean
Whether the request is an asynchronous request
36 37 38 |
# File 'lib/autoforme/frameworks/roda.rb', line 36 def xhr? @env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i end |