Class: JsDuck::Util::Stdout

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/jsduck/util/stdout.rb

Overview

Central place for buffering JSON data that’s meant to be written to STDOUT

Instance Method Summary collapse

Methods included from Singleton

included

Constructor Details

#initializeStdout

Returns a new instance of Stdout.



11
12
13
# File 'lib/jsduck/util/stdout.rb', line 11

def initialize
  @data = nil
end

Instance Method Details

#add(data) ⇒ Object

Adds array of new data



16
17
18
19
20
21
22
# File 'lib/jsduck/util/stdout.rb', line 16

def add(data)
  if @data
    @data += data
  else
    @data = data
  end
end

#flushObject

Writes data to STDOUT in JSON format, but only if some data was added.



26
27
28
# File 'lib/jsduck/util/stdout.rb', line 26

def flush
  puts Util::Json.generate(@data) if @data
end