Class: Flatrack::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/flatrack/request.rb

Overview

parses an incoming flatrack request and provides a method to render a response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Request

Initializes a response

Parameters:

  • env (Hash)

    the rack env



9
10
11
12
# File 'lib/flatrack/request.rb', line 9

def initialize(env)
  @rack_request = Rack::Request.new(env)
  @env          = env
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



5
6
7
# File 'lib/flatrack/request.rb', line 5

def env
  @env
end

#rack_requestObject (readonly)

Returns the value of attribute rack_request.



5
6
7
# File 'lib/flatrack/request.rb', line 5

def rack_request
  @rack_request
end

Instance Method Details

#formatObject

the format on the incoming request



25
26
27
28
29
30
31
# File 'lib/flatrack/request.rb', line 25

def format
  ext = File.extname path
  unless ext.empty?
    path.sub!(/#{ext}/, '')
    ext.split('.').last
  end
end

#paramsObject

the params on the incoming request



20
21
22
# File 'lib/flatrack/request.rb', line 20

def params
  rack_request.params.with_indifferent_access
end

#pathObject

the path of the incoming request



15
16
17
# File 'lib/flatrack/request.rb', line 15

def path
  env['PATH_INFO']
end

#responseObject

the processed response for an inbound request



34
35
36
37
38
39
40
# File 'lib/flatrack/request.rb', line 34

def response
  Response.new(self).render
rescue TemplateNotFound
  respond_with_error(500)
rescue FileNotFound
  respond_with_error(404)
end