Guest User

Untitled

a guest
Jul 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. class ResponsePadder
  2. def initialize (app, minlength, pad=' ', &condition)
  3. @app = app
  4. @minlength = minlength
  5. @pad = pad
  6. @condition = condition
  7. end
  8.  
  9. def call (env)
  10. response = @app.call(env)
  11. if @condition.call(response)
  12. @body = response[2]
  13. response[2] = self
  14. end
  15. response
  16. end
  17.  
  18. def each
  19. length = 0
  20. @body.each do |part|
  21. length += part.length
  22. yield part
  23. end
  24.  
  25. yield @pad * (@minlength-length) unless length >= @minlength
  26. end
  27. end
Add Comment
Please, Sign In to add comment