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, 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 (action=nil)

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

[show source]
# File lib/autoforme/frameworks/roda.rb, line 52
def csrf_token_hash(action=nil)
  if @controller.respond_to?(:check_csrf!)
    # Using route_csrf plugin
    # :nocov:
    token = if @controller.use_request_specific_csrf_tokens?
      @controller.csrf_token(@controller.csrf_path(action))
    else
      @controller.csrf_token
    end
    {@controller.csrf_field=>token}
    # :nocov:
  elsif defined?(::Rack::Csrf)
    {::Rack::Csrf.field=>::Rack::Csrf.token(@env)}
  end
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
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, line 41
def set_flash_notice(message)
  @controller.flash[flash_symbol_keys? ? :notice : 'notice'] = message
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, line 47
def set_flash_now_error(message)
  @controller.flash.now[flash_symbol_keys? ? :error : 'error'] = message
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