Class: Canon::Config::DiffConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/canon/config.rb

Overview

Diff configuration for output formatting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format = nil) ⇒ DiffConfig

Returns a new instance of DiffConfig.



296
297
298
299
300
# File 'lib/canon/config.rb', line 296

def initialize(format = nil)
  @format = format
  @resolver = build_resolver(format)
  @pretty_printer = PrettyPrinterConfig.new(@resolver)
end

Instance Attribute Details

#pretty_printerObject (readonly)

Returns the value of attribute pretty_printer.



294
295
296
# File 'lib/canon/config.rb', line 294

def pretty_printer
  @pretty_printer
end

Instance Method Details

#algorithmObject



642
643
644
# File 'lib/canon/config.rb', line 642

def algorithm
  @resolver.resolve(:algorithm)
end

#algorithm=(value) ⇒ Object



646
647
648
# File 'lib/canon/config.rb', line 646

def algorithm=(value)
  @resolver.set_programmatic(:algorithm, value)
end

#apply_profile_data(data) ⇒ Object



307
308
309
310
311
312
313
314
# File 'lib/canon/config.rb', line 307

def apply_profile_data(data)
  return unless data

  data.each do |key, value|
    sym_key = key.to_sym
    @resolver.set_profile(sym_key, coerce_profile_value(sym_key, value))
  end
end

#character_visualizationObject

Controls whether invisible characters (spaces, tabs, non-breaking spaces, etc.) are replaced with visible Unicode symbols in diff output.

Values:

true          - apply the full default visualization map (default)
false         - disable visualization; output plain text
:content_only - reserved for future use; currently behaves as +true+.
                Future intent: apply visualization only to DOM text
                node content, not to structural indentation whitespace.
                (TODO: implement DOM-level pre-serialization pass)


627
628
629
630
631
632
633
634
635
636
# File 'lib/canon/config.rb', line 627

def character_visualization
  val = @resolver.resolve(:character_visualization)
  # Coerce symbol booleans that may arrive via ENV (env_schema uses :symbol type
  # so "true"/"false" env strings become :true/:false symbols)
  case val
  when true, :true then true # rubocop:disable Lint/BooleanSymbol
  when false, :false then false # rubocop:disable Lint/BooleanSymbol
  else val # true/false from programmatic, or :content_only
  end
end

#character_visualization=(value) ⇒ Object



638
639
640
# File 'lib/canon/config.rb', line 638

def character_visualization=(value)
  @resolver.set_programmatic(:character_visualization, value)
end

#clear_profile!Object



316
317
318
# File 'lib/canon/config.rb', line 316

def clear_profile!
  @resolver.clear_profile!
end

#collapse_whitespace_elementsObject

Element names where whitespace is COLLAPSED (HTML-style behavior). Multiple whitespace chars collapse to single space; boundaries preserved. ENV variable: CANON_<FORMAT>_DIFF_COLLAPSE_WHITESPACE_ELEMENTS



532
533
534
# File 'lib/canon/config.rb', line 532

def collapse_whitespace_elements
  @resolver.resolve(:collapse_whitespace_elements) || []
end

#collapse_whitespace_elements=(value) ⇒ Object



536
537
538
539
# File 'lib/canon/config.rb', line 536

def collapse_whitespace_elements=(value)
  @resolver.set_programmatic(:collapse_whitespace_elements,
                             Array(value).map(&:to_s))
end

#compact_semantic_reportObject

Render element nodes in the Semantic Diff Report as compact inline XML (e.g. <strong>Annex</strong>) instead of the verbose node_info description string (e.g. “name: strong namespace_uri: …”).

Default: false (keep existing verbose format for backwards compatibility) ENV variable: CANON_<FORMAT>_DIFF_COMPACT_SEMANTIC_REPORT



596
597
598
# File 'lib/canon/config.rb', line 596

def compact_semantic_report
  @resolver.resolve(:compact_semantic_report)
end

#compact_semantic_report=(value) ⇒ Object



600
601
602
# File 'lib/canon/config.rb', line 600

def compact_semantic_report=(value)
  @resolver.set_programmatic(:compact_semantic_report, value)
end

#context_linesObject



337
338
339
# File 'lib/canon/config.rb', line 337

def context_lines
  @resolver.resolve(:context_lines)
end

#context_lines=(value) ⇒ Object



341
342
343
# File 'lib/canon/config.rb', line 341

def context_lines=(value)
  @resolver.set_programmatic(:context_lines, value)
end

#display_formatObject



493
494
495
# File 'lib/canon/config.rb', line 493

def display_format
  @resolver.resolve(:display_format)
end

#display_format=(value) ⇒ Object



497
498
499
# File 'lib/canon/config.rb', line 497

def display_format=(value)
  @resolver.set_programmatic(:display_format, value)
end

#display_preprocessingObject

Controls how documents are normalized *for display* before the line diff. This is independent of FormatConfig#preprocessing, which controls normalization for comparison (equivalence detection).

Values:

:none         - use documents as-is (default, existing behaviour)
:pretty_print - run through Canon::PrettyPrinter::Xml before diffing
:c14n         - run through XML C14N normalization before diffing


509
510
511
# File 'lib/canon/config.rb', line 509

def display_preprocessing
  @resolver.resolve(:display_preprocessing)
end

#display_preprocessing=(value) ⇒ Object



513
514
515
# File 'lib/canon/config.rb', line 513

def display_preprocessing=(value)
  @resolver.set_programmatic(:display_preprocessing, value)
end

#expand_differenceObject

Show the full serialized node content (including children) in element_structure diffs instead of just the tag name.

Default: false (show only the tag name, e.g. <biblio-tag>) ENV variable: CANON_<FORMAT>_DIFF_EXPAND_DIFFERENCE



609
610
611
# File 'lib/canon/config.rb', line 609

def expand_difference
  @resolver.resolve(:expand_difference)
end

#expand_difference=(value) ⇒ Object



613
614
615
# File 'lib/canon/config.rb', line 613

def expand_difference=(value)
  @resolver.set_programmatic(:expand_difference, value)
end

#grouping_linesObject



345
346
347
# File 'lib/canon/config.rb', line 345

def grouping_lines
  @resolver.resolve(:grouping_lines)
end

#grouping_lines=(value) ⇒ Object



349
350
351
# File 'lib/canon/config.rb', line 349

def grouping_lines=(value)
  @resolver.set_programmatic(:grouping_lines, value)
end

#max_diff_linesObject

Maximum diff output lines (default 10,000)



678
679
680
# File 'lib/canon/config.rb', line 678

def max_diff_lines
  @resolver.resolve(:max_diff_lines)
end

#max_diff_lines=(value) ⇒ Object



682
683
684
# File 'lib/canon/config.rb', line 682

def max_diff_lines=(value)
  @resolver.set_programmatic(:max_diff_lines, value)
end

#max_file_sizeObject

File size limit in bytes (default 5MB)



660
661
662
# File 'lib/canon/config.rb', line 660

def max_file_size
  @resolver.resolve(:max_file_size)
end

#max_file_size=(value) ⇒ Object



664
665
666
# File 'lib/canon/config.rb', line 664

def max_file_size=(value)
  @resolver.set_programmatic(:max_file_size, value)
end

#max_node_countObject

Maximum node count in tree (default 10,000)



669
670
671
# File 'lib/canon/config.rb', line 669

def max_node_count
  @resolver.resolve(:max_node_count)
end

#max_node_count=(value) ⇒ Object



673
674
675
# File 'lib/canon/config.rb', line 673

def max_node_count=(value)
  @resolver.set_programmatic(:max_node_count, value)
end

#modeObject

Accessors with ENV override support



321
322
323
# File 'lib/canon/config.rb', line 321

def mode
  @resolver.resolve(:mode)
end

#mode=(value) ⇒ Object



325
326
327
# File 'lib/canon/config.rb', line 325

def mode=(value)
  @resolver.set_programmatic(:mode, value)
end

#preserve_whitespace_elementsObject

Element names where whitespace is PRESERVED exactly (no manipulation). All whitespace characters are significant in these elements. ENV variable: CANON_<FORMAT>_DIFF_PRESERVE_WHITESPACE_ELEMENTS



520
521
522
# File 'lib/canon/config.rb', line 520

def preserve_whitespace_elements
  @resolver.resolve(:preserve_whitespace_elements) || []
end

#preserve_whitespace_elements=(value) ⇒ Object



524
525
526
527
# File 'lib/canon/config.rb', line 524

def preserve_whitespace_elements=(value)
  @resolver.set_programmatic(:preserve_whitespace_elements,
                             Array(value).map(&:to_s))
end

#pretty_printed_expectedObject

When true, whitespace-only text nodes starting with “n” in :collapse elements of the expected (fixture) document are treated as structural indentation and dropped from both comparison and display. Use this when fixture files are indented but received XML is compact. ENV variable: CANON_<FORMAT>_DIFF_PRETTY_PRINTED_EXPECTED



557
558
559
# File 'lib/canon/config.rb', line 557

def pretty_printed_expected
  @resolver.resolve(:pretty_printed_expected)
end

#pretty_printed_expected=(value) ⇒ Object



561
562
563
# File 'lib/canon/config.rb', line 561

def pretty_printed_expected=(value)
  @resolver.set_programmatic(:pretty_printed_expected, value)
end

#pretty_printed_receivedObject

When true, whitespace-only text nodes starting with “n” in :normalize elements of the received document are treated as structural indentation and dropped from both comparison and display. Use this when received XML may be pretty-printed but the fixture is compact. ENV variable: CANON_<FORMAT>_DIFF_PRETTY_PRINTED_RECEIVED



570
571
572
# File 'lib/canon/config.rb', line 570

def pretty_printed_received
  @resolver.resolve(:pretty_printed_received)
end

#pretty_printed_received=(value) ⇒ Object



574
575
576
# File 'lib/canon/config.rb', line 574

def pretty_printed_received=(value)
  @resolver.set_programmatic(:pretty_printed_received, value)
end

#pretty_printer_sort_attributesObject

When true, attributes on each element are sorted by namespace URI then local name in the pretty-printed display, eliminating spurious diff noise from differing attribute order. ENV variable: CANON_<FORMAT>_DIFF_PRETTY_PRINTER_SORT_ATTRIBUTES



582
583
584
# File 'lib/canon/config.rb', line 582

def pretty_printer_sort_attributes
  @resolver.resolve(:pretty_printer_sort_attributes)
end

#pretty_printer_sort_attributes=(value) ⇒ Object



586
587
588
# File 'lib/canon/config.rb', line 586

def pretty_printer_sort_attributes=(value)
  @resolver.set_programmatic(:pretty_printer_sort_attributes, value)
end

#reset!Object



302
303
304
305
# File 'lib/canon/config.rb', line 302

def reset!
  @resolver = build_resolver(@format)
  @pretty_printer = PrettyPrinterConfig.new(@resolver)
end

#show_diffsObject



353
354
355
# File 'lib/canon/config.rb', line 353

def show_diffs
  @resolver.resolve(:show_diffs)
end

#show_diffs=(value) ⇒ Object



357
358
359
# File 'lib/canon/config.rb', line 357

def show_diffs=(value)
  @resolver.set_programmatic(:show_diffs, value)
end

#show_line_numbered_inputsObject



485
486
487
# File 'lib/canon/config.rb', line 485

def show_line_numbered_inputs
  @resolver.resolve(:show_line_numbered_inputs)
end

#show_line_numbered_inputs=(value) ⇒ Object



489
490
491
# File 'lib/canon/config.rb', line 489

def show_line_numbered_inputs=(value)
  @resolver.set_programmatic(:show_line_numbered_inputs, value)
end

#show_preprocessed_expectedObject

Show only the EXPECTED (fixture) block in the preprocessed-inputs section. Has no effect unless show_preprocessed_inputs or verbose_diff is also set. Use show_preprocessed_expected: true together with show_preprocessed_received: false to display only the preprocessed fixture while suppressing the preprocessed received output.

ENV variable: CANON_<FORMAT>_DIFF_SHOW_PREPROCESSED_EXPECTED



421
422
423
# File 'lib/canon/config.rb', line 421

def show_preprocessed_expected
  @resolver.resolve(:show_preprocessed_expected)
end

#show_preprocessed_expected=(value) ⇒ Object



425
426
427
# File 'lib/canon/config.rb', line 425

def show_preprocessed_expected=(value)
  @resolver.set_programmatic(:show_preprocessed_expected, value)
end

#show_preprocessed_inputsObject



406
407
408
# File 'lib/canon/config.rb', line 406

def show_preprocessed_inputs
  @resolver.resolve(:show_preprocessed_inputs)
end

#show_preprocessed_inputs=(value) ⇒ Object



410
411
412
# File 'lib/canon/config.rb', line 410

def show_preprocessed_inputs=(value)
  @resolver.set_programmatic(:show_preprocessed_inputs, value)
end

#show_preprocessed_receivedObject

Show only the RECEIVED (actual) block in the preprocessed-inputs section. Combined with show_preprocessed_expected: false (or leaving it at the default false) this suppresses the fixture preprocessing display while still showing what the received document looked like after preprocessing.

ENV variable: CANON_<FORMAT>_DIFF_SHOW_PREPROCESSED_RECEIVED



436
437
438
# File 'lib/canon/config.rb', line 436

def show_preprocessed_received
  @resolver.resolve(:show_preprocessed_received)
end

#show_preprocessed_received=(value) ⇒ Object



440
441
442
# File 'lib/canon/config.rb', line 440

def show_preprocessed_received=(value)
  @resolver.set_programmatic(:show_preprocessed_received, value)
end

#show_prettyprint_expectedObject

Show only the EXPECTED (fixture) block in the pretty-print section. Useful when the fixture is what needs updating and the received side is not needed for copy-pasting.

ENV variable: CANON_<FORMAT>_DIFF_SHOW_PRETTYPRINT_EXPECTED



464
465
466
# File 'lib/canon/config.rb', line 464

def show_prettyprint_expected
  @resolver.resolve(:show_prettyprint_expected)
end

#show_prettyprint_expected=(value) ⇒ Object



468
469
470
# File 'lib/canon/config.rb', line 468

def show_prettyprint_expected=(value)
  @resolver.set_programmatic(:show_prettyprint_expected, value)
end

#show_prettyprint_inputsObject

Show both EXPECTED and RECEIVED blocks in a fixture-ready pretty-printed section. The output uses the same pretty-printer as display_preprocessing: :pretty_print (one tag per line, indentation) but with no character visualization — whitespace appears as plain ASCII so the output can be copy-pasted directly into RSpec fixture heredocs.

ENV variable: CANON_<FORMAT>_DIFF_SHOW_PRETTYPRINT_INPUTS



451
452
453
# File 'lib/canon/config.rb', line 451

def show_prettyprint_inputs
  @resolver.resolve(:show_prettyprint_inputs)
end

#show_prettyprint_inputs=(value) ⇒ Object



455
456
457
# File 'lib/canon/config.rb', line 455

def show_prettyprint_inputs=(value)
  @resolver.set_programmatic(:show_prettyprint_inputs, value)
end

#show_prettyprint_receivedObject

Show only the RECEIVED (actual) block in the pretty-print section. Use this to get a copy-pasteable pretty-printed form of the generated output (the most common fixture-update workflow).

ENV variable: CANON_<FORMAT>_DIFF_SHOW_PRETTYPRINT_RECEIVED



477
478
479
# File 'lib/canon/config.rb', line 477

def show_prettyprint_received
  @resolver.resolve(:show_prettyprint_received)
end

#show_prettyprint_received=(value) ⇒ Object



481
482
483
# File 'lib/canon/config.rb', line 481

def show_prettyprint_received=(value)
  @resolver.set_programmatic(:show_prettyprint_received, value)
end

#show_raw_expectedObject

Show only the EXPECTED (fixture) block in the raw-inputs section. Has no effect unless show_raw_inputs or verbose_diff is also set. Use show_raw_expected: false together with show_raw_received: true (or show_raw_inputs: true) to suppress the fixture display while keeping the received output.

ENV variable: CANON_<FORMAT>_DIFF_SHOW_RAW_EXPECTED



384
385
386
# File 'lib/canon/config.rb', line 384

def show_raw_expected
  @resolver.resolve(:show_raw_expected)
end

#show_raw_expected=(value) ⇒ Object



388
389
390
# File 'lib/canon/config.rb', line 388

def show_raw_expected=(value)
  @resolver.set_programmatic(:show_raw_expected, value)
end

#show_raw_inputsObject



369
370
371
# File 'lib/canon/config.rb', line 369

def show_raw_inputs
  @resolver.resolve(:show_raw_inputs)
end

#show_raw_inputs=(value) ⇒ Object



373
374
375
# File 'lib/canon/config.rb', line 373

def show_raw_inputs=(value)
  @resolver.set_programmatic(:show_raw_inputs, value)
end

#show_raw_receivedObject

Show only the RECEIVED (actual) block in the raw-inputs section. Combined with show_raw_expected: false (or leaving it at the default false) this suppresses the fixture while still displaying the output that was generated.

ENV variable: CANON_<FORMAT>_DIFF_SHOW_RAW_RECEIVED



398
399
400
# File 'lib/canon/config.rb', line 398

def show_raw_received
  @resolver.resolve(:show_raw_received)
end

#show_raw_received=(value) ⇒ Object



402
403
404
# File 'lib/canon/config.rb', line 402

def show_raw_received=(value)
  @resolver.set_programmatic(:show_raw_received, value)
end

#strip_whitespace_elementsObject

Element names where whitespace-only text nodes are STRIPPED. ENV variable: CANON_<FORMAT>_DIFF_STRIP_WHITESPACE_ELEMENTS



543
544
545
# File 'lib/canon/config.rb', line 543

def strip_whitespace_elements
  @resolver.resolve(:strip_whitespace_elements) || []
end

#strip_whitespace_elements=(value) ⇒ Object



547
548
549
550
# File 'lib/canon/config.rb', line 547

def strip_whitespace_elements=(value)
  @resolver.set_programmatic(:strip_whitespace_elements,
                             Array(value).map(&:to_s))
end

#themeObject

Theme name (:light, :dark, :retro, :claude)



651
652
653
# File 'lib/canon/config.rb', line 651

def theme
  @resolver.resolve(:theme)
end

#theme=(value) ⇒ Object



655
656
657
# File 'lib/canon/config.rb', line 655

def theme=(value)
  @resolver.set_programmatic(:theme, value)
end

#to_hObject

Build diff options



687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
# File 'lib/canon/config.rb', line 687

def to_h
  {
    diff: mode,
    use_color: use_color,
    context_lines: context_lines,
    grouping_lines: grouping_lines,
    show_diffs: show_diffs,
    verbose_diff: verbose_diff,
    diff_algorithm: algorithm,
    show_raw_inputs: show_raw_inputs,
    show_raw_expected: show_raw_expected,
    show_raw_received: show_raw_received,
    show_preprocessed_inputs: show_preprocessed_inputs,
    show_preprocessed_expected: show_preprocessed_expected,
    show_preprocessed_received: show_preprocessed_received,
    show_prettyprint_inputs: show_prettyprint_inputs,
    show_prettyprint_expected: show_prettyprint_expected,
    show_prettyprint_received: show_prettyprint_received,
    show_line_numbered_inputs: show_line_numbered_inputs,
    character_visualization: character_visualization,
    display_format: display_format,
    display_preprocessing: display_preprocessing,
    pretty_printer_indent: pretty_printer.indent,
    pretty_printer_indent_type: pretty_printer.indent_type,
    preserve_whitespace_elements: preserve_whitespace_elements,
    collapse_whitespace_elements: collapse_whitespace_elements,
    strip_whitespace_elements: strip_whitespace_elements,
    pretty_printed_expected: pretty_printed_expected,
    pretty_printed_received: pretty_printed_received,
    compact_semantic_report: compact_semantic_report,
    expand_difference: expand_difference,
    max_file_size: max_file_size,
    max_node_count: max_node_count,
    max_diff_lines: max_diff_lines,
    theme: theme,
  }
end

#use_colorObject



329
330
331
# File 'lib/canon/config.rb', line 329

def use_color
  @resolver.resolve(:use_color)
end

#use_color=(value) ⇒ Object



333
334
335
# File 'lib/canon/config.rb', line 333

def use_color=(value)
  @resolver.set_programmatic(:use_color, value)
end

#verbose_diffObject



361
362
363
# File 'lib/canon/config.rb', line 361

def verbose_diff
  @resolver.resolve(:verbose_diff)
end

#verbose_diff=(value) ⇒ Object



365
366
367
# File 'lib/canon/config.rb', line 365

def verbose_diff=(value)
  @resolver.set_programmatic(:verbose_diff, value)
end