Class: Vanilla::Request
- Inherits:
-
Object
- Object
- Vanilla::Request
- Defined in:
- lib/vanilla/request.rb
Overview
Create a request with symbolised access to the params, and some special accessors to the snip, part and format based on our routing.
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#part ⇒ Object
readonly
Returns the value of attribute part.
-
#snip_name ⇒ Object
readonly
Returns the value of attribute snip_name.
Instance Method Summary collapse
- #cookies ⇒ Object
-
#initialize(env) ⇒ Request
constructor
A new instance of Request.
- #ip ⇒ Object
- #params ⇒ Object
- #session ⇒ Object
-
#snip ⇒ Object
Returns the snip referenced by the request’s URL.
Constructor Details
#initialize(env) ⇒ Request
Returns a new instance of Request.
9 10 11 12 |
# File 'lib/vanilla/request.rb', line 9 def initialize(env) @rack_request = Rack::Request.new(env) determine_request_uri_parts end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
7 8 9 |
# File 'lib/vanilla/request.rb', line 7 def format @format end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
7 8 9 |
# File 'lib/vanilla/request.rb', line 7 def method @method end |
#part ⇒ Object (readonly)
Returns the value of attribute part.
7 8 9 |
# File 'lib/vanilla/request.rb', line 7 def part @part end |
#snip_name ⇒ Object (readonly)
Returns the value of attribute snip_name.
7 8 9 |
# File 'lib/vanilla/request.rb', line 7 def snip_name @snip_name end |
Instance Method Details
#cookies ⇒ Object
25 26 27 |
# File 'lib/vanilla/request.rb', line 25 def @rack_request. end |
#ip ⇒ Object
29 30 31 |
# File 'lib/vanilla/request.rb', line 29 def ip @rack_request.env["REMOTE_ADDR"] end |
#params ⇒ Object
14 15 16 17 |
# File 'lib/vanilla/request.rb', line 14 def params # Don't you just love how terse functional programming tends to look like maths? @symbolised_params ||= @rack_request.params.inject({}) { |p, (k,v)| p[k.to_sym] = v; p } end |
#session ⇒ Object
33 34 35 |
# File 'lib/vanilla/request.rb', line 33 def session @rack_request.env["rack.session"] end |
#snip ⇒ Object
Returns the snip referenced by the request’s URL. Performs no exception handling, so if the snip does not exist, an exception will be thrown.
21 22 23 |
# File 'lib/vanilla/request.rb', line 21 def snip Vanilla.snip(snip_name) end |