class Flatrack::Request
parses an incoming flatrack request and provides a method to render a response
Attributes
env[R]
rack_request[R]
Public Class Methods
new(env)
click to toggle source
Initializes a response @param env [Hash] the rack env
# File lib/flatrack/request.rb, line 9 def initialize(env) @rack_request = Rack::Request.new(env) @env = env end
Public Instance Methods
config()
click to toggle source
# File lib/flatrack/request.rb, line 48 def config env['flatrack.config'] end
format()
click to toggle source
the format on the incoming request
# File lib/flatrack/request.rb, line 29 def format ext = File.extname path unless ext.empty? path.sub!(/#{ext}/, '') ext.split('.').last end end
mount_path()
click to toggle source
# File lib/flatrack/request.rb, line 52 def mount_path env['SCRIPT_NAME'].present? ? env['SCRIPT_NAME'] : '/' end
page()
click to toggle source
# File lib/flatrack/request.rb, line 19 def page env['PATH_INFO'] end
params()
click to toggle source
the params on the incoming request
# File lib/flatrack/request.rb, line 24 def params rack_request.params.with_indifferent_access end
path()
click to toggle source
the path of the incoming request
# File lib/flatrack/request.rb, line 15 def path env['ORIGINAL_PATH_INFO'] || env['PATH_INFO'] end
response()
click to toggle source
the processed response for an inbound request
# File lib/flatrack/request.rb, line 38 def response Response.new(self).render rescue TemplateNotFound => e raise e if config.raise_errors respond_with_error(500) rescue FileNotFound => e raise e if config.raise_errors respond_with_error(404) end
Private Instance Methods
respond_with_error(code)
click to toggle source
# File lib/flatrack/request.rb, line 58 def respond_with_error(code) Response.new(self).render(file: code, status: code) rescue FileNotFound file = File.join Flatrack.gem_root, '../error_pages', "#{code}.html" Response.new(self).render(file: file, status: code) end