Skip to content

Instantly share code, notes, and snippets.

@Twisol
Created February 6, 2011 03:11
Show Gist options
  • Save Twisol/813068 to your computer and use it in GitHub Desktop.
Save Twisol/813068 to your computer and use it in GitHub Desktop.
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