Class: Meddler::PostInterceptor
- Inherits:
-
Object
- Object
- Meddler::PostInterceptor
- Defined in:
- lib/meddler.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#signal ⇒ Object
readonly
Returns the value of attribute signal.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, rules, filters, signal) ⇒ PostInterceptor
constructor
A new instance of PostInterceptor.
Constructor Details
#initialize(app, rules, filters, signal) ⇒ PostInterceptor
Returns a new instance of PostInterceptor.
40 41 42 43 44 45 |
# File 'lib/meddler.rb', line 40 def initialize(app, rules, filters, signal) @app = app @rules = rules @filters = filters @signal = signal end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
39 40 41 |
# File 'lib/meddler.rb', line 39 def app @app end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
39 40 41 |
# File 'lib/meddler.rb', line 39 def filters @filters end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
39 40 41 |
# File 'lib/meddler.rb', line 39 def rules @rules end |
#signal ⇒ Object (readonly)
Returns the value of attribute signal.
39 40 41 |
# File 'lib/meddler.rb', line 39 def signal @signal end |
Instance Method Details
#call(env) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/meddler.rb', line 47 def call(env) raw_response = app.call(env) response = Rack::Response.new(raw_response[2], raw_response[0], raw_response[1]) if rules.nil? || rules.all?{|r| r.call(response)} filters && filters.each{|f| f.call(response)} [response.status, response.headers, response.body] else throw signal, [response.status, response.headers, response.body, signal] end end |