refactored

This commit is contained in:
Blake Mizerany 2007-11-25 18:24:27 -08:00
parent 323cd705f9
commit 63f81c967e
2 changed files with 12 additions and 12 deletions

View File

@ -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

View File

@ -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