Module: Newark::App
- Defined in:
- lib/newark/app.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- FOUR_O_FOUR =
[ 404, {}, [] ].freeze
- HTTP_VERBS =
[ :delete, :get, :head, :options, :patch, :post, :put, :trace ].freeze
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #_call(env) ⇒ Object
- #call(env) ⇒ Object
- #headers ⇒ Object
- #initialize ⇒ Object
- #params ⇒ Object
- #route ⇒ Object
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
47 48 49 |
# File 'lib/newark/app.rb', line 47 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
47 48 49 |
# File 'lib/newark/app.rb', line 47 def response @response end |
Class Method Details
.included(klass) ⇒ Object
10 11 12 13 |
# File 'lib/newark/app.rb', line 10 def self.included(klass) klass.instance_variable_set :@routes, {} klass.extend ClassMethods end |
Instance Method Details
#_call(env) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/newark/app.rb', line 60 def _call(env) @env = env @request = Request.new(@env) @response = Response.new route end |
#call(env) ⇒ Object
56 57 58 |
# File 'lib/newark/app.rb', line 56 def call(env) dup._call(env) end |
#headers ⇒ Object
67 68 69 |
# File 'lib/newark/app.rb', line 67 def headers response.headers end |
#initialize ⇒ Object
49 50 51 52 53 54 |
# File 'lib/newark/app.rb', line 49 def initialize(*) super @before_hooks = self.class.instance_variable_get(:@before_hooks) @after_hooks = self.class.instance_variable_get(:@after_hooks) @routes = self.class.instance_variable_get(:@routes) end |
#params ⇒ Object
71 72 73 |
# File 'lib/newark/app.rb', line 71 def params request.params end |
#route ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/newark/app.rb', line 75 def route route = match_route if route if exec_before_hooks response.body = exec(route.handler) exec_after_hooks end status, headers, body = response.finish [status, headers, body.respond_to?(:body) ? body.body : body] else FOUR_O_FOUR end end |