summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGibheer <gibheer@gmail.com>2012-10-06 20:18:30 +0200
committerGibheer <gibheer@gmail.com>2012-10-06 20:18:30 +0200
commit92e199d5db76c5fdebf58af53fc7557b42c06b3e (patch)
tree0ed0b1413971c9b3f2817a1ff39cadac9084797e /lib
parent3ec99843eb0e9df7c23996893441c526ae7f2f3f (diff)
Rack::Response and Rack::Request work pretty good
Diffstat (limited to 'lib')
-rw-r--r--lib/zero/controller.rb19
-rw-r--r--lib/zero/request.rb11
-rw-r--r--lib/zero/response.rb22
3 files changed, 8 insertions, 44 deletions
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