From 63f81c967e590eb565f49e8b051a0bacd2631d72 Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Sun, 25 Nov 2007 18:24:27 -0800 Subject: [PATCH] refactored --- lib/sinatra.rb | 20 ++++++++------------ test/filter_test.rb | 4 ++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/sinatra.rb b/lib/sinatra.rb index 749fb930..d237f7d7 100644 --- a/lib/sinatra.rb +++ b/lib/sinatra.rb @@ -305,27 +305,23 @@ module Sinatra def handle_with_filters(groups, cx, &b) caught = catch(:halt) do - filters_to_run = filters[:before][:all] - filters_to_run += groups.inject([]) do |m, g| - m + filters[:before][g] - end - filters_to_run.each { |x| cx.instance_eval(&x) } + filters_for(:before, groups).each { |x| cx.instance_eval(&x) } [:complete, b] end caught = catch(:halt) do caught.to_result(cx) end result = caught.to_result(cx) if caught - - filters_to_run = filters[:after][:all] - filters_to_run += groups.inject([]) do |m, g| - m + filters[:after][g] - end - filters_to_run.each { |x| cx.instance_eval(&x) } - + filters_for(:after, groups).each { |x| cx.instance_eval(&x) } cx.body Array(result.to_s) cx end + + def filters_for(type, groups) + filters[type][:all] + groups.inject([]) do |m, g| + m + filters[type][g] + end + end class Route diff --git a/test/filter_test.rb b/test/filter_test.rb index 2b3d76fa..d6febca8 100644 --- a/test/filter_test.rb +++ b/test/filter_test.rb @@ -69,6 +69,10 @@ context "Filters" do end context "Filter grouping" do + + setup do + Sinatra.reset! + end specify "befores only run for groups if specified" do