Browse files

Add support for the to_result idiom back in but deprecate (#56)

  • Loading branch information...
1 parent f41472f commit 9ab1b600c9486b5456b16a1acae5ab855036d7a1 @rtomayko rtomayko committed Jan 10, 2009
Showing with 17 additions and 4 deletions.
  1. +0 −4 lib/sinatra/base.rb
  2. +17 −0 lib/sinatra/compat.rb
View
4 lib/sinatra/base.rb
@@ -386,16 +386,12 @@ def invoke(handler)
else
@response.body = res
end
- when res.kind_of?(Symbol) # TODO: deprecate this.
- @response.body = __send__(res)
when res.respond_to?(:each)
@response.body = res
when (100...599) === res
@response.status = res
when res.nil?
@response.body = []
- else
- raise TypeError, "#{res.inspect} not supported"
end
res
end
View
17 lib/sinatra/compat.rb
@@ -102,6 +102,23 @@ def send_file(path, opts={})
super(path, opts)
end
+ # Throwing halt with a Symbol and the to_result convention are
+ # deprecated. Override the invoke method to detect those types of return
+ # values.
+ def invoke(handler)
+ res = super
+ case
+ when res.kind_of?(Symbol)
+ sinatra_warn "Invoking the :#{res} helper by returning a Symbol is deprecated;",
+ "call the helper directly instead."
+ @response.body = __send__(res)
+ when res.respond_to?(:to_result)
+ sinatra_warn "The to_result convention is deprecated."
+ @response.body = res.to_result(self)
+ end
+ res
+ end
+
def options
Options.new(self.class)
end

0 comments on commit 9ab1b60

Please sign in to comment.