lib/angelo/responder.rb in angelo-0.3.3 vs lib/angelo/responder.rb in angelo-0.4.0

- old
+ new

@@ -23,21 +23,17 @@ def default_headers @default_headers ||= DEFAULT_RESPONSE_HEADERS @default_headers end - def symhash - Hash.new {|hash,key| hash[key.to_s] if Symbol === key } - end - end - attr_accessor :connection, :request + attr_accessor :connection, :mustermann, :request attr_writer :base def initialize &block - @response_handler = Base.compile! :request_handler, &block + @response_handler = block end def reset! @params = nil @redirect = nil @@ -46,11 +42,11 @@ end def handle_request if @response_handler @base.filter :before - @body = catch(:halt) { @response_handler.bind(@base).call || EMPTY_STRING } + @body = catch(:halt) { @base.instance_exec(&@response_handler) || EMPTY_STRING } # TODO any real reason not to run afters with SSE? case @body when HALT_STRUCT @base.filter :after if @body.body != :sse @@ -162,11 +158,16 @@ when NilClass @body = EMPTY_STRING else - unless @chunked and @body.respond_to? :each - raise RequestError.new "what is this? #{@body}" + if respond_with? :json and @body.respond_to? :to_json + @body = @body.to_json + raise "uhhh? #{@body}" unless String === @body + else + unless @chunked and @body.respond_to? :each + raise RequestError.new "what is this? #{@body}" + end end end status ||= @redirect.nil? ? :ok : :moved_permanently headers LOCATION_HEADER_KEY => @redirect if @redirect