Class: WorklessChecker
- Inherits:
-
Object
- Object
- WorklessChecker
- Defined in:
- lib/workless/middleware/workless_checker.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#empty?(response) ⇒ Boolean
fix issue if response’s body is a Proc.
-
#file?(headers) ⇒ Boolean
if send file?.
-
#initialize(app) ⇒ WorklessChecker
constructor
A new instance of WorklessChecker.
Constructor Details
#initialize(app) ⇒ WorklessChecker
Returns a new instance of WorklessChecker.
4 5 6 |
# File 'lib/workless/middleware/workless_checker.rb', line 4 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/workless/middleware/workless_checker.rb', line 8 def call(env) status, headers, response = @app.call(env) return [status, headers, response] if file?(headers) || empty?(response) Delayed::Job.scaler.up unless Delayed::Job.scaler.jobs.empty? [status, headers, response] end |
#empty?(response) ⇒ Boolean
fix issue if response’s body is a Proc
18 19 20 21 22 23 24 |
# File 'lib/workless/middleware/workless_checker.rb', line 18 def empty?(response) # response may be ["Not Found"], ["Move Permanently"], etc. (response.is_a?(Array) && response.size <= 1) || !response.respond_to?(:body) || !response.body.respond_to?(:empty?) || response.body.empty? end |
#file?(headers) ⇒ Boolean
if send file?
27 28 29 |
# File 'lib/workless/middleware/workless_checker.rb', line 27 def file?(headers) headers['Content-Transfer-Encoding'] == 'binary' end |