Class used when the response body is set explicitly, instead of using Roda’s default body array and response.write to write to it.
Public Class methods
new(&block)
Save the block that will return the body, it won’t be called until the body is needed.
[show source]
# File lib/roda/plugins/sinatra_helpers.rb 214 def initialize(&block) 215 @block = block 216 @value = nil 217 end
Public Instance methods
each()
If the body is a String, yield it, otherwise yield each string returned by calling each on the body.
[show source]
# File lib/roda/plugins/sinatra_helpers.rb 221 def each 222 v = value 223 if v.is_a?(String) 224 yield v 225 else 226 v.each{|s| yield s} 227 end 228 end
empty?()
Assume that if the body has been set directly that it is never empty.
[show source]
# File lib/roda/plugins/sinatra_helpers.rb 232 def empty? 233 false 234 end
join()
Return the body as a single string, mostly useful during testing.
[show source]
# File lib/roda/plugins/sinatra_helpers.rb 237 def join 238 a = [] 239 each{|s| a << s} 240 a.join 241 end
length()
Calculate the length for the body.
[show source]
# File lib/roda/plugins/sinatra_helpers.rb 244 def length 245 length = 0 246 each{|s| length += s.bytesize} 247 length 248 end