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
214 def initialize(&block)
215   @block = block
216 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
220 def each
221   v = value
222   if v.is_a?(String)
223     yield v
224   else
225     v.each{|s| yield s}
226   end
227 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
231 def empty?
232   false
233 end
join()

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

[show source]
    # File lib/roda/plugins/sinatra_helpers.rb
236 def join
237   a = []
238   each{|s| a << s}
239   a.join
240 end
length()

Calculate the length for the body.

[show source]
    # File lib/roda/plugins/sinatra_helpers.rb
243 def length
244   length = 0
245   each{|s| length += s.bytesize}
246   length
247 end