Top Level Namespace
Defined Under Namespace
Modules: UnderRack
Instance Method Summary collapse
- #delete(path, &block) ⇒ Object
- #erb(view_name) ⇒ Object
- #general_request_method(request_method, path, &block) ⇒ Object
- #get(path, &block) ⇒ Object
- #post(path, &block) ⇒ Object
- #put(path, &block) ⇒ Object
Instance Method Details
#delete(path, &block) ⇒ Object
68 69 70 |
# File 'lib/under_rack/framework.rb', line 68 def delete(path, &block) general_request_method("DELETE", path, &block) end |
#erb(view_name) ⇒ Object
3 4 5 6 7 |
# File 'lib/under_rack/framework.rb', line 3 def erb(view_name) view = File.read("#{view_name.to_s}.erb") body = ERB.new(view) body.result(binding) end |
#general_request_method(request_method, path, &block) ⇒ Object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/under_rack/framework.rb', line 1 def general_request_method(request_method, path, &block) def erb(view_name) view = File.read("#{view_name.to_s}.erb") body = ERB.new(view) body.result(binding) end middleware = Class.new middleware.send(:define_method, 'initialize') do |app| @app = app end middleware.send(:define_method, 'call') do |env| request = Rack::Request.new(env) response = Rack::Response.new if request.request_method == self.class.request_method && request.path_info == self.class.path response.write(action) response.finish else if @app.respond_to? :call @app.call(env) else [404, {"Content-Type" => "text/html"}, ["Not Found"]] end end end middleware.instance_eval do def path=(path) @path = path end def path @path end def request_method=(rm) @rm = rm end def request_method @rm end end middleware.send(:define_method, 'action', &block) middleware.path = path middleware.request_method = request_method use middleware middleware end |
#get(path, &block) ⇒ Object
56 57 58 |
# File 'lib/under_rack/framework.rb', line 56 def get(path, &block) general_request_method("GET", path, &block) end |
#post(path, &block) ⇒ Object
60 61 62 |
# File 'lib/under_rack/framework.rb', line 60 def post(path, &block) general_request_method("POST", path, &block) end |
#put(path, &block) ⇒ Object
64 65 66 |
# File 'lib/under_rack/framework.rb', line 64 def put(path, &block) general_request_method("PUT", path, &block) end |