1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

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) def handle_with_filters(groups, cx, &b)
caught = catch(:halt) do caught = catch(:halt) do
filters_to_run = filters[:before][:all] filters_for(:before, groups).each { |x| cx.instance_eval(&x) }
filters_to_run += groups.inject([]) do |m, g|
m + filters[:before][g]
end
filters_to_run.each { |x| cx.instance_eval(&x) }
[:complete, b] [:complete, b]
end end
caught = catch(:halt) do caught = catch(:halt) do
caught.to_result(cx) caught.to_result(cx)
end end
result = caught.to_result(cx) if caught result = caught.to_result(cx) if caught
filters_for(:after, groups).each { |x| cx.instance_eval(&x) }
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) }
cx.body Array(result.to_s) cx.body Array(result.to_s)
cx cx
end end
def filters_for(type, groups)
filters[type][:all] + groups.inject([]) do |m, g|
m + filters[type][g]
end
end
class Route class Route

View file

@ -69,6 +69,10 @@ context "Filters" do
end end
context "Filter grouping" do context "Filter grouping" do
setup do
Sinatra.reset!
end
specify "befores only run for groups if specified" do specify "befores only run for groups if specified" do