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
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#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
- #authenticate! ⇒ Object
- #authenticated? ⇒ Boolean
- #cookies ⇒ Object
-
#initialize(env, app) ⇒ Request
constructor
A new instance of Request.
- #ip ⇒ Object
- #logout ⇒ Object
- #params ⇒ Object
- #session ⇒ Object
-
#snip ⇒ Object
Returns the snip referenced by the request’s URL.
- #user ⇒ Object
Constructor Details
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
7 8 9 |
# File 'lib/vanilla/request.rb', line 7 def env @env end |
#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
#authenticate! ⇒ Object
47 48 49 |
# File 'lib/vanilla/request.rb', line 47 def authenticate! @app.authenticator.authenticate! end |
#authenticated? ⇒ Boolean
39 40 41 |
# File 'lib/vanilla/request.rb', line 39 def authenticated? @app.authenticator.authenticated? end |
#cookies ⇒ Object
27 28 29 |
# File 'lib/vanilla/request.rb', line 27 def @rack_request. end |
#ip ⇒ Object
31 32 33 |
# File 'lib/vanilla/request.rb', line 31 def ip @rack_request.env["REMOTE_ADDR"] end |
#logout ⇒ Object
51 52 53 |
# File 'lib/vanilla/request.rb', line 51 def logout @app.authenticator.logout end |
#params ⇒ Object
16 17 18 19 |
# File 'lib/vanilla/request.rb', line 16 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
35 36 37 |
# File 'lib/vanilla/request.rb', line 35 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.
23 24 25 |
# File 'lib/vanilla/request.rb', line 23 def snip @app.soup[snip_name] end |
#user ⇒ Object
43 44 45 |
# File 'lib/vanilla/request.rb', line 43 def user @app.authenticator.user end |