Module: Roda::RodaPlugins::RequestAref

Defined in:
lib/roda/plugins/request_aref.rb

Overview

The request_aref plugin allows for custom handling of the r[] and r[]= methods (where r is the Request instance). In the current version of rack, these methods are deprecated, but the deprecation message is only printed in verbose mode. This plugin can allow for handling calls to these methods in one of three ways:

:allow

Allow the method calls without a deprecation, which is the historical behavior

:warn

Always issue a deprecation message by calling warn, not just in verbose mode.

:raise

Raise an error if either method is called

Defined Under Namespace

Modules: RequestMethods Classes: Error

Class Method Summary collapse

Class Method Details

.configure(app, setting) ⇒ Object

Make #[] and #[]= methods work as configured by aliasing the appropriate request_a(ref|set)_* methods to them.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/roda/plugins/request_aref.rb', line 20

def self.configure(app, setting)
  case setting
  when :allow, :raise, :warn
    app::RodaRequest.class_eval do
      alias_method(:[],  :"request_aref_#{setting}")
      alias_method(:[]=, :"request_aset_#{setting}")
      public :[], :[]=
    end
  else
    raise RodaError, "Unsupport request_aref plugin setting: #{setting.inspect}"
  end
end