class Roda::RodaPlugins::SinatraHelpers::DelayedBody

  1. lib/roda/plugins/sinatra_helpers.rb
Superclass: Object

Class used when the response body is set explicitly, instead of using Roda’s default body array and response.write to write to it.

Methods

Public Class

  1. new

Public Instance

  1. each
  2. empty?
  3. join
  4. length

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
246 def initialize(&block)
247   @block = block
248 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
252 def each
253   v = value
254   if v.is_a?(String)
255     yield v
256   else
257     v.each{|s| yield s}
258   end
259 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
263 def empty?
264   false
265 end
join()

Return the body as a single string, mostly useful during testing.

[show source]
    # File lib/roda/plugins/sinatra_helpers.rb
268 def join
269   a = []
270   each{|s| a << s}
271   a.join
272 end
length()

Calculate the length for the body.

[show source]
    # File lib/roda/plugins/sinatra_helpers.rb
275 def length
276   length = 0
277   each{|s| length += s.bytesize}
278   length
279 end