Class: Spore::Middleware
- Inherits:
-
Object
- Object
- Spore::Middleware
- Defined in:
- lib/spore/middleware.rb,
lib/spore/middleware/format.rb,
lib/spore/middleware/runtime.rb
Defined Under Namespace
Classes: ExpectedParam, Format, Runtime
Instance Method Summary collapse
-
#expected_params ⇒ Object
overide this list in your middleware if you need to store some atteributes and make sure they’re initialized when the middleware is enabled.
-
#initialize(args) ⇒ Middleware
constructor
you should not need to overrride this one.
-
#process_request(env) ⇒ Object
This is where your middleware can handle an incoming request before it’s executed (the env hash contains anything to build the query) if you want to halt the process of the request, return a Net::HTTP response object if you just want to alter the env hash, do it and return nil.
-
#process_response(response, env) ⇒ Object
This is where your middleware can alter the response object Make sure you return always the response object.
Constructor Details
#initialize(args) ⇒ Middleware
you should not need to overrride this one
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/spore/middleware.rb', line 16 def initialize(args) for param in self.expected_params if not args.has_key?(param) raise ExpectedParam, "param '#{param}' is expected" end self.class.send(:attr_accessor, param.to_sym) eval "self.#{param} = args[param]" end end |
Instance Method Details
#expected_params ⇒ Object
overide this list in your middleware if you need to store some atteributes and make sure they’re initialized when the middleware is enabled
11 12 13 |
# File 'lib/spore/middleware.rb', line 11 def expected_params [] end |
#process_request(env) ⇒ Object
This is where your middleware can handle an incoming request before it’s executed (the env hash contains anything to build the query) if you want to halt the process of the request, return a Net::HTTP response object if you just want to alter the env hash, do it and return nil
32 33 |
# File 'lib/spore/middleware.rb', line 32 def process_request(env) end |
#process_response(response, env) ⇒ Object
This is where your middleware can alter the response object
Make sure you return always the response object
37 38 39 |
# File 'lib/spore/middleware.rb', line 37 def process_response(response, env) return response end |