From b72f00cc22b9fc02e61a2859c40e125b7985454a Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Wed, 28 Nov 2007 21:28:59 -0800 Subject: [PATCH] this should be stop and body= should go to @response --- lib/sinatra.rb | 23 +++++++++++++---------- test/app_test.rb | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/sinatra.rb b/lib/sinatra.rb index f496e1e..9c66eec 100644 --- a/lib/sinatra.rb +++ b/lib/sinatra.rb @@ -124,7 +124,7 @@ module Sinatra attr_accessor :request, :response - dslify_writter :status + dslify_writter :status, :body def initialize(request, response, route_params) @request = request @@ -137,7 +137,7 @@ module Sinatra @params ||= @route_params.merge(@request.params).symbolize_keys end - def body(content) + def stop(content) throw :halt, content end @@ -147,12 +147,7 @@ module Sinatra private - def _body=(content) - @response.body = content - end - def method_missing(name, *args, &b) - raise NoMethodError.new('body=') if name == :body= @response.send(name, *args, &b) end @@ -166,7 +161,7 @@ module Sinatra def to_result(cx, *args) cx.status(302) cx.header.merge!('Location' => @path) - cx.send :_body=, '' + cx.body = '' end end @@ -203,7 +198,7 @@ module Sinatra [:complete, context.instance_eval(&result.block)] end result = returned.to_result(context) - context.send :_body=, String === result ? [*result] : result + context.body = String === result ? [*result] : result context.finish end @@ -318,7 +313,7 @@ end class String def to_result(cx, *args) - cx.send :_body=, self + cx.body = self end end @@ -340,3 +335,11 @@ class Fixnum cx.body args.first end end + +class NilClass + def to_result(cx, *args) + cx.body = '' + # log warning here + end +end + diff --git a/test/app_test.rb b/test/app_test.rb index 8eb1ee8..a6d6a99 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -40,8 +40,8 @@ context "Sinatra" do Sinatra::EventContext.any_instance.expects(:foo).never get '/set_body' do - body 'Hello!' - body 'Not this' + stop 'Hello!' + stop 'World!' foo end -- 2.11.4.GIT