Class: TemplateStreaming::StreamingBody

Inherits:
Object
  • Object
show all
Defined in:
lib/template_streaming.rb

Instance Method Summary collapse

Constructor Details

#initialize(threshold, &block) ⇒ StreamingBody

Returns a new instance of StreamingBody.



317
318
319
320
# File 'lib/template_streaming.rb', line 317

def initialize(threshold, &block)
  @process = block
  @bytes_to_threshold = threshold
end

Instance Method Details

#each(&block) ⇒ Object



322
323
324
325
# File 'lib/template_streaming.rb', line 322

def each(&block)
  @push = block
  @process.call
end

#push(data) ⇒ Object



327
328
329
330
331
332
333
334
# File 'lib/template_streaming.rb', line 327

def push(data)
  if @bytes_to_threshold > 0
    @push.call(data + padding(@bytes_to_threshold - data.length))
    @bytes_to_threshold = 0
  else
    @push.call(data)
  end
end