-
-
Save jbarnette/469890 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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