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
-
#initialize(env, app) ⇒ Request
constructor
A new instance of Request.
- #method_missing(name, *args) ⇒ Object
-
#params ⇒ Object
returns the parameters of the request, with every key as a symbol.
-
#snip ⇒ Object
Returns the snip referenced by the request’s URL.
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/vanilla/request.rb', line 27 def method_missing(name, *args) if @rack_request.respond_to?(name) @rack_request.send(name, *args) else super end end |
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
#params ⇒ Object
returns the parameters of the request, with every key as a symbol
17 18 19 |
# File 'lib/vanilla/request.rb', line 17 def params @symbolised_params ||= @rack_request.params.inject({}) { |p, (k,v)| p[k.to_sym] = v; p } 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 |