Class: Nimble::Main
- Inherits:
-
Object
- Object
- Nimble::Main
- Defined in:
- lib/nimble_framework.rb
Constant Summary collapse
- @@routes =
Hash.new { |hash, key| hash[key] = Hash.new }
Class Attribute Summary collapse
-
.routes ⇒ Object
Returns the value of attribute routes.
Class Method Summary collapse
- .call(env) ⇒ Object
- .delete(route, &block) ⇒ Object
- .erb(view_name, locals = {}) ⇒ Object
- .get(route, &block) ⇒ Object
- .params ⇒ Object
- .post(route, &block) ⇒ Object
- .put(route, &block) ⇒ Object
- .redirect_to(path) ⇒ Object
- .session ⇒ Object
Class Attribute Details
.routes ⇒ Object
Returns the value of attribute routes.
11 12 13 |
# File 'lib/nimble_framework.rb', line 11 def routes @routes end |
Class Method Details
.call(env) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/nimble_framework.rb', line 49 def call(env) @request = Rack::Request.new(env) block = @@routes[@request.request_method][@request.path_info] if block @params = @request.params @response = Rack::Response.new @response.body = [block.call] @response.header ||= {} @response.status ||= 200 @response.finish else [404, {}, ["Page not found"]] end end |
.delete(route, &block) ⇒ Object
25 26 27 |
# File 'lib/nimble_framework.rb', line 25 def delete(route, &block) @@routes['DELETE'][route] = block end |
.erb(view_name, locals = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/nimble_framework.rb', line 29 def erb(view_name, locals = {}) path = ::File.join("views", "#{view_name.to_s}.html.erb") template = Tilt.new(path) template.render(nil, locals) end |
.get(route, &block) ⇒ Object
13 14 15 |
# File 'lib/nimble_framework.rb', line 13 def get(route, &block) @@routes['GET'][route] = block end |
.params ⇒ Object
39 40 41 |
# File 'lib/nimble_framework.rb', line 39 def params @params end |
.post(route, &block) ⇒ Object
17 18 19 |
# File 'lib/nimble_framework.rb', line 17 def post(route, &block) @@routes['POST'][route] = block end |
.put(route, &block) ⇒ Object
21 22 23 |
# File 'lib/nimble_framework.rb', line 21 def put(route, &block) @@routes['PUT'][route] = block end |
.redirect_to(path) ⇒ Object
43 44 45 46 47 |
# File 'lib/nimble_framework.rb', line 43 def redirect_to(path) @response['Location'] = path @response.status = 303 "Redirect!" end |
.session ⇒ Object
35 36 37 |
# File 'lib/nimble_framework.rb', line 35 def session @request.session end |