Class: OctocatalogDiff::Cli::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/octocatalog-diff/cli/printer.rb

Overview

Wrapper around OctocatalogDiff::CatalogDiff::Display to set the options and output to a file or the screen depending on selection.

Instance Method Summary collapse

Constructor Details

#initialize(options, logger) ⇒ Printer

Constructor

Parameters:

  • options (Hash)

    Options from cli/options

  • logger (Logger)

    Logger object



14
15
16
17
# File 'lib/octocatalog-diff/cli/printer.rb', line 14

def initialize(options, logger)
  @options = options
  @logger = logger
end

Instance Method Details

#printer(diffs, from_dir = nil, to_dir = nil) ⇒ Object

The method to call externally, passing in diffs. This takes the appropriate action based on options, which is either to write the result into an output file, or print the result on STDOUT. Does not return anything.

Parameters:

  • diffs (Array<Diffs>)

    Array of differences

  • from_dir (String) (defaults to: nil)

    Directory in which “from” catalog was compiled

  • to_dir (String) (defaults to: nil)

    Directory in which “to” catalog was compiled



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/octocatalog-diff/cli/printer.rb', line 25

def printer(diffs, from_dir = nil, to_dir = nil)
  unless diffs.is_a?(Array)
    raise ArgumentError, "printer() expects an array, not #{diffs.class}"
  end
  display_opts = @options.merge(compilation_from_dir: from_dir, compilation_to_dir: to_dir)
  diff_text = OctocatalogDiff::CatalogDiff::Display.output(diffs, display_opts, @logger)
  if @options[:output_file].nil?
    puts diff_text unless diff_text.empty?
  else
    output_to_file(diff_text)
  end
end