Class: OctocatalogDiff::Cli::Printer
- Inherits:
-
Object
- Object
- OctocatalogDiff::Cli::Printer
- 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
-
#initialize(options, logger) ⇒ Printer
constructor
Constructor.
-
#printer(diffs, from_dir = nil, to_dir = nil) ⇒ Object
The method to call externally, passing in diffs.
Constructor Details
#initialize(options, logger) ⇒ Printer
Constructor
14 15 16 17 |
# File 'lib/octocatalog-diff/cli/printer.rb', line 14 def initialize(, logger) @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.
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 |