diff --git a/lib/zero/controller.rb b/lib/zero/controller.rb index 30d6632..6c64d8f 100644 --- a/lib/zero/controller.rb +++ b/lib/zero/controller.rb @@ -1,29 +1,26 @@ module Zero - # abstract class to make creation of controllers easier # # This abstract class creates an interface to make it easier to write # rack compatible controllers. It catches #call and creates a new instance # with the environment and calls #render on it. class Controller + # initialize a new instance of the controller and call response on it def self.call(env) - new(Request.new(env)).response + new(Rack::Request.new(env)).response end + # initialize the controller + # @param Request a request object def initialize(request) @request = request - @code = 200 - @header = {} - @body = '' + @response = Rack::Response.new end + # build the response and return it + # @return Response a rack conform response def response - render - [@code, @header, [@body]] - end - - def render - raise NotImplementedError.new + raise NotImplementedError.new("Not Implemented in ${__FILE__}") end end end diff --git a/lib/zero/request.rb b/lib/zero/request.rb deleted file mode 100644 index f5109a7..0000000 --- a/lib/zero/request.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Zero - # encapsulate the rack environment - class Request - attr_reader :env - - # create a new - def initialize(env) - @env = env - end - end -end diff --git a/lib/zero/response.rb b/lib/zero/response.rb deleted file mode 100644 index 470b76d..0000000 --- a/lib/zero/response.rb +++ /dev/null @@ -1,22 +0,0 @@ -module Zero - # an easier interface for the response - # - # The response for rack has to be an array of three elements. This class makes - # it easier to fill all the needed data. - class Response - attr_accessor :code, :header, :body - - # init a new response - def initialize - @code = 404 - @header = {} - @body = nil - end - - # builds the response for rack and checks for protocol errors - # @return Array the rack response - def to_a - [@code, @header, [@body]] - end - end -end