Created
February 6, 2011 03:11
-
-
Save Twisol/813068 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ResponsePadder | |
def initialize (app, minlength, pad=' ', &condition) | |
@app = app | |
@minlength = minlength | |
@pad = pad | |
@condition = condition | |
end | |
def call (env) | |
response = @app.call(env) | |
if @condition.call(response) | |
@body = response[2] | |
response[2] = self | |
end | |
response | |
end | |
def each | |
length = 0 | |
@body.each do |part| | |
length += part.length | |
yield part | |
end | |
yield @pad * (@minlength-length) unless length >= @minlength | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment