Module: Roy::Before

Defined in:
lib/roy/before.rb

Overview

This module allows you to modify the environment before it is handled by the application. It does this by overriding the #call method.

Configuration:

roy.conf.before

A proc object that will be called with the environment as argument. Defaults to identity if not set.

Examples:

Forcing a method


class AlwaysGet
  include Roy

  roy allow: [:put, :post], use: [:before],
      before: ->(env) { env['REQUEST_METHOD'] = 'GET' }

  def get(_)
    "Hello, world\n"
  end
end

Demo


$ curl -i localhost:9292
HTTP/1.1 200 OK
$ curl -X POST -i localhost:9292
HTTP/1.1 200 OK
$ curl -X PUT -i localhost:9292
HTTP/1.1 200 OK

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



32
33
34
35
# File 'lib/roy/before.rb', line 32

def call(env)
  (roy.conf.before || lambda {|x| x }).(env)
  super
end