@@ -327,14 +327,17 @@ def self.make_trailing_whitespace_visible(string_in)
327
327
# @param depth [Fixnum] Depth, for correct indentation
328
328
# @param limit [Fixnum] Maximum string length
329
329
# @param strip_diff [Boolean] Strip leading +/-/" "
330
- # @return Array<String> Displayable result
330
+ # @return [ Array<String>] Displayable result
331
331
def self . diff_two_hashes_with_diffy ( opts = { } )
332
332
depth = opts . fetch ( :depth , 0 )
333
333
hash1 = opts . fetch ( :hash1 , { } )
334
334
hash2 = opts . fetch ( :hash2 , { } )
335
335
limit = opts [ :limit ]
336
336
strip_diff = opts . fetch ( :strip_diff , false )
337
337
338
+ # Special case: addition only, no truncation
339
+ return addition_only_no_truncation ( depth , hash2 , strip_diff ) if hash1 == { } && limit . nil?
340
+
338
341
json_old = stringify_for_diffy ( hash1 )
339
342
json_new = stringify_for_diffy ( hash2 )
340
343
@@ -354,6 +357,32 @@ def self.diff_two_hashes_with_diffy(opts = {})
354
357
end
355
358
end
356
359
360
+ # Special case: addition only, no truncation
361
+ # @param depth [Fixnum] Depth, for correct indentation
362
+ # @param hash [Hash] Added object
363
+ # @param strip_diff [Boolean] Strip leading +/-/" "
364
+ # @return [Array<String>] Displayable result
365
+ def self . addition_only_no_truncation ( depth , hash , strip_diff )
366
+ plus = strip_diff ? '' : '+ '
367
+ result = [ ]
368
+
369
+ # Single line strings
370
+ hash . keys . sort . map do |key |
371
+ next if hash [ key ] =~ /\n /
372
+ result << left_pad ( 2 * depth + 2 , [ plus , key . inspect , ': ' , hash [ key ] . inspect ] . join ( '' ) ) . green
373
+ end
374
+
375
+ # Multi-line strings
376
+ hash . keys . sort . map do |key |
377
+ next if hash [ key ] !~ /\n /
378
+ result << left_pad ( 2 * depth + 2 , [ plus , key . inspect , ': >>>' ] . join ( '' ) ) . green
379
+ result . concat hash [ key ] . split ( /\n / ) . map ( &:green )
380
+ result << '<<<'
381
+ end
382
+
383
+ result
384
+ end
385
+
357
386
# Limit length of a string
358
387
# @param str [String] String
359
388
# @param limit [Fixnum] Limit (0=unlimited)
0 commit comments