diff options
-rw-r--r-- | lib/zero/controller.rb | 13 | ||||
-rw-r--r-- | lib/zero/request.rb | 11 | ||||
-rw-r--r-- | lib/zero/response.rb | 22 |
3 files changed, 46 insertions, 0 deletions
diff --git a/lib/zero/controller.rb b/lib/zero/controller.rb new file mode 100644 index 0000000..4264de1 --- /dev/null +++ b/lib/zero/controller.rb @@ -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 diff --git a/lib/zero/request.rb b/lib/zero/request.rb new file mode 100644 index 0000000..f5109a7 --- /dev/null +++ b/lib/zero/request.rb @@ -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 diff --git a/lib/zero/response.rb b/lib/zero/response.rb new file mode 100644 index 0000000..0527b07 --- /dev/null +++ b/lib/zero/response.rb @@ -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 |