Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment