Class: StoryTeller::IO::OutputBuffer

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

Overview

The OutputBuffer class

Instance Method Summary collapse

Constructor Details

#initializeOutputBuffer

Returns a new instance of OutputBuffer.



149
150
151
152
# File 'lib/story_teller/session.rb', line 149

def initialize
  @content = String.new # rubocop: disable Style/EmptyLiteral
  @mutex = Mutex.new
end

Instance Method Details

#drainObject



160
161
162
163
164
165
166
# File 'lib/story_teller/session.rb', line 160

def drain
  @mutex.synchronize do
    content = @content.dup
    @content.clear
    content.strip.length.positive? ? content : ''
  end
end

#resetObject



168
169
170
# File 'lib/story_teller/session.rb', line 168

def reset
  @mutex.synchronize { @content.clear }
end

#write(value) ⇒ Object



154
155
156
157
158
# File 'lib/story_teller/session.rb', line 154

def write(value)
  return if value.nil?

  @mutex.synchronize { @content << value.to_s }
end