Skip to content

Instantly share code, notes, and snippets.

@jbarnette
Forked from tenderlove/config.ru
Created July 9, 2010 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jbarnette/469890 to your computer and use it in GitHub Desktop.
Save jbarnette/469890 to your computer and use it in GitHub Desktop.
class Intercession
def initialize app, behavior
@app = app
@behavior = behavior
@before, @after = %w(before after).map { |m| @behavior.instance_methods.map(&:to_s).include? m }
end
def call env
session = env["rack.session"] and session.extend @behavior
session.before if @before.to_s == "true"
@app.call(env).tap { session.after if @after.to_s == "true" }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment