Class: Test::Unit::UI::Launchable::JSON::JSONStreamWriter::KeyValueWriter
- Inherits:
-
Object
- Object
- Test::Unit::UI::Launchable::JSON::JSONStreamWriter::KeyValueWriter
- Defined in:
- lib/test/unit/ui/launchable/json/testrunner.rb
Instance Method Summary collapse
- #close ⇒ Object
- #close_array ⇒ Object
-
#initialize(file, indent) ⇒ KeyValueWriter
constructor
A new instance of KeyValueWriter.
- #open_array(key) ⇒ Object
- #open_nested_object {|KeyValueWriter.new(@file, @indent)| ... } ⇒ Object
- #write_key_value(key, value) ⇒ Object
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
#close ⇒ Object
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_array ⇒ Object
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
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 |