Class: AutoForme::Frameworks::Roda::Request

Inherits:
Request
  • Object
show all
Defined in:
lib/autoforme/frameworks/roda.rb

Instance Attribute Summary

Attributes inherited from Request

#action_type, #controller, #id, #method, #model, #params, #path, #session

Instance Method Summary collapse

Methods inherited from Request

#post?, #query_string, #set_flash_notice, #set_flash_now_error

Constructor Details

#initialize(roda, path) ⇒ Request

Returns a new instance of Request.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/autoforme/frameworks/roda.rb', line 5

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
    @env['PATH_INFO']
  end
  @id = @params['id'] || ($1 if remaining_path =~ %r{\A\/(\w+)\z})
end

Instance Method Details

#csrf_token_hashObject

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



35
36
37
# File 'lib/autoforme/frameworks/roda.rb', line 35

def csrf_token_hash
  {::Rack::Csrf.field=>::Rack::Csrf.token(@env)} if defined?(::Rack::Csrf)
end

#redirect(path) ⇒ Object

Redirect to the given path



25
26
27
# File 'lib/autoforme/frameworks/roda.rb', line 25

def redirect(path)
  @request.redirect(path)
end

#xhr?Boolean

Whether the request is an asynchronous request

Returns:

  • (Boolean)


30
31
32
# File 'lib/autoforme/frameworks/roda.rb', line 30

def xhr?
  @env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i
end