class Rigle::Application
Public Instance Methods
call(env)
click to toggle source
# File lib/rigle.rb, line 6 def call(env) case env['PATH_INFO'] when '/favicon.ico' return render_html(status: 404, content: []) when '/' return redirect_to(path: '/quotes/quote') end klass, act = get_controller_and_action(env) controller = klass.new(env) begin text = controller.send(act) render_html(status: 200, content: [text]) rescue render_html(status: 500, content: [ '<p>Huston, we have a problem!</p>', %q(<p>Told you, there's no place like <a href="http://localhost:3001/">home</a>...</p>) ]) end end
get_controller_and_action(env)
click to toggle source
# File lib/rigle/routing.rb, line 3 def get_controller_and_action(env) _, cont, action, after = env['PATH_INFO'].split('/', 4) cont = cont.capitalize # People cont += 'Controller' # PeopleController [Object.const_get(cont), action] end
Private Instance Methods
redirect_to(path:)
click to toggle source
# File lib/rigle.rb, line 33 def redirect_to(path:) headers = { 'Content-Type' => 'text/html', 'Location' => path } [302, headers, ['302 you are being redirected']] end
render_html(status:, content:)
click to toggle source
# File lib/rigle.rb, line 29 def render_html(status:, content:) [status, {'Content-Type' => 'text/html'}, content] end