0
0
Fork 0

added some basic structures

This commit is contained in:
Gibheer 2012-10-05 07:54:17 +02:00
parent c2c053a73b
commit bc34186b23
3 changed files with 46 additions and 0 deletions

13
lib/zero/controller.rb Normal file
View File

@ -0,0 +1,13 @@
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
def self << call(env)
new(Request.new(env)).render
end
end
end

11
lib/zero/request.rb Normal file
View File

@ -0,0 +1,11 @@
module Zero
# encapsulate the rack environment
class Request
attr_reader :env
# create a new
def initialize(env)
@env = env
end
end
end

22
lib/zero/response.rb Normal file
View File

@ -0,0 +1,22 @@
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_reader :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 response
end
end
end