Class: OctocatalogDiff::CatalogDiff::Display::Json

Inherits:
OctocatalogDiff::CatalogDiff::Display show all
Defined in:
lib/octocatalog-diff/catalog-diff/display/json.rb

Overview

Display the output from a diff in JSON format. This is the new format, used in octocatalog-diff 1.x, where each diff is represented by an hash with named keys.

Class Method Summary collapse

Methods inherited from OctocatalogDiff::CatalogDiff::Display

header, output, parse_diff_array_into_categorized_hashes, simple_deep_merge!

Class Method Details

.generate(diff, options = {}, _logger = nil) ⇒ Object

Generate JSON representation of the ‘diff’ suitable for further analysis.

Parameters:

  • diff (Array<Diff results>)

    The diff which must be in this format

  • options (Hash) (defaults to: {})

    Options which are:

    • :header => [String] Header to print; no header is printed if not specified

  • _logger (Logger) (defaults to: nil)

    Not used here



18
19
20
21
22
23
24
# File 'lib/octocatalog-diff/catalog-diff/display/json.rb', line 18

def self.generate(diff, options = {}, _logger = nil)
  result = {
    'diff' => diff.map(&:to_h_with_string_keys)
  }
  result['header'] = options[:header] unless options[:header].nil?
  result.to_json
end