Module: Roy::After

Defined in:
lib/roy/after.rb

Overview

This module allows you to modify the response before it is sent to the client. It does this by overriding the #call method.

Related options:

roy.conf.after

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

Examples:

Forcing a custom content-type


class SetContentType
  include Roy

  roy use: [:after],
      after: ->(resp) { resp.headers['Content-Type'] = 'text/x-foo' }

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

Demo


Instance Method Summary (collapse)

Instance Method Details

- (Object) call(env)



29
30
31
32
33
34
# File 'lib/roy/after.rb', line 29

def call(env)
  status, header, body = super
  resp = Rack::Response.new(body, status, header)
  (roy.conf.after || lambda {|x| x }).(resp)
  resp.finish
end