Class: TemplateStreaming::StreamingBody
- Inherits:
-
Object
- Object
- TemplateStreaming::StreamingBody
- Defined in:
- lib/template_streaming.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(threshold, &block) ⇒ StreamingBody
constructor
A new instance of StreamingBody.
- #push(data) ⇒ Object
Constructor Details
#initialize(threshold, &block) ⇒ StreamingBody
Returns a new instance of StreamingBody.
250 251 252 253 |
# File 'lib/template_streaming.rb', line 250 def initialize(threshold, &block) @process = block @bytes_to_threshold = threshold end |
Instance Method Details
#each(&block) ⇒ Object
255 256 257 258 |
# File 'lib/template_streaming.rb', line 255 def each(&block) @push = block @process.call end |
#push(data) ⇒ Object
260 261 262 263 264 265 266 267 |
# File 'lib/template_streaming.rb', line 260 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 |