Module: KongSchema::Reporter

Extended by:
Reporter
Included in:
Reporter
Defined in:
lib/kong_schema/reporter.rb

Overview

Helper class for printing a report of the changes to be committed to Kong created by Schema.analyze.

Defined Under Namespace

Classes: JSONPrettyPrinter, YAMLPrettyPrinter

Constant Summary collapse

TableHeader =
%w(Change Parameters).freeze

Instance Method Summary collapse

Instance Method Details

#report(changes, object_format: :json) ⇒ String

Returns The report to print to something like STDOUT.

Parameters:

  • changes (Array<KongSchema::Action>)

    What you get from calling Schema.analyze

Returns:

  • (String)

    The report to print to something like STDOUT.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kong_schema/reporter.rb', line 22

def report(changes, object_format: :json)
  pretty_print = if object_format == :json
    JSONPrettyPrinter.method(:print)
  else
    YAMLPrettyPrinter.method(:print)
  end

  table = TTY::Table.new header: TableHeader do |t|
    changes.each do |change|
      t << print_change(change: change, pretty_print: pretty_print)
    end
  end

  table.render(:ascii, multiline: true, padding: [0, 1, 0, 1])
end