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. xhr?

Public Class methods

new (roda, path)
[show source]
# File lib/autoforme/frameworks/roda.rb, line 6
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

Public Instance methods

csrf_token_hash ()

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

[show source]
# File lib/autoforme/frameworks/roda.rb, line 40
def csrf_token_hash
  {::Rack::Csrf.field=>::Rack::Csrf.token(@env)} if defined?(::Rack::Csrf)
end
redirect (path)

Redirect to the given path

[show source]
# File lib/autoforme/frameworks/roda.rb, line 30
def redirect(path)
  @request.redirect(path)
end
xhr? ()

Whether the request is an asynchronous request

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