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 ⇒ 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.
-
#xhr? ⇒ Boolean
Whether the request is an asynchronous request.
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.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 @env['PATH_INFO'] end path_id = $1 if remaining_path =~ %r{\A\/([\w-]+)\z} set_id(path_id) end |
Instance Method Details
#csrf_token_hash ⇒ Object
Use Rack::Csrf for csrf protection if it is defined.
39 40 41 |
# File 'lib/autoforme/frameworks/roda.rb', line 39 def csrf_token_hash {::Rack::Csrf.field=>::Rack::Csrf.token(@env)} if defined?(::Rack::Csrf) end |
#redirect(path) ⇒ Object
Redirect to the given path
29 30 31 |
# File 'lib/autoforme/frameworks/roda.rb', line 29 def redirect(path) @request.redirect(path) end |
#xhr? ⇒ Boolean
Whether the request is an asynchronous request
34 35 36 |
# File 'lib/autoforme/frameworks/roda.rb', line 34 def xhr? @env['HTTP_X_REQUESTED_WITH'] =~ /XMLHttpRequest/i end |