Class: Test::Unit::UI::Launchable::JSON::JSONStreamWriter::KeyValueWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/test/unit/ui/launchable/json/testrunner.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, indent) ⇒ KeyValueWriter

Returns a new instance of KeyValueWriter.



150
151
152
153
154
155
# File 'lib/test/unit/ui/launchable/json/testrunner.rb', line 150

def initialize(file, indent)
  @indent = indent
  @file = file
  @is_first_key_val = true
  @is_first_element = true
end

Instance Method Details

#closeObject



196
197
198
199
200
201
# File 'lib/test/unit/ui/launchable/json/testrunner.rb', line 196

def close
  @indent -= 2
  @file.puts
  write_indent
  @file.write("}")
end

#close_arrayObject



220
221
222
223
224
# File 'lib/test/unit/ui/launchable/json/testrunner.rb', line 220

def close_array
  @file.puts
  write_indent
  @file.puts("]")
end

#open_array(key) ⇒ Object



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/test/unit/ui/launchable/json/testrunner.rb', line 203

def open_array(key)
  if @is_first_key_val
    @is_first_key_val = false
  else
    write_comma
  end
  write_indent
  @file.write(to_json_str(key))
  write_colon
  @file.write(" ")
  @file.write("[")
  yield
  @file.puts
  write_indent
  @file.write("]")
end

#open_nested_object {|KeyValueWriter.new(@file, @indent)| ... } ⇒ Object

Yields:



170
171
172
173
174
# File 'lib/test/unit/ui/launchable/json/testrunner.rb', line 170

def open_nested_object
  @file.puts("{")
  @indent += 2
  @writer = KeyValueWriter.new(file, @indent)
end

#write_key_value(key, value) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/test/unit/ui/launchable/json/testrunner.rb', line 157

def write_key_value(key, value)
  if @is_first_key_val
    @is_first_key_val = false
  else
    write_comma
  end
  @file.puts
  write_indent
  @file.write(to_json_str(key))
  @file.write(":", " ")
  @file.write(to_json_str(value))
end