Class: OctocatalogDiff::Cli::Diffs

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

Overview

Wrapper around OctocatalogDiff::CatalogDiff::Differ to provide the logger object, set up ignores, and add additional ignores for items dependent upon the compilation directory.

Instance Method Summary collapse

Constructor Details

#initialize(options, logger) ⇒ Diffs

Constructor

Parameters:

  • options (Hash)

    Options from cli/options

  • logger (Logger)

    Logger object


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

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

Instance Method Details

#diffs(catalogs) ⇒ Array<diffs>

The method to call externally, passing in the catalogs as a hash (see parameter). This sets up options and ignores and then actually performs the diffs. The result is the array of diffs.

Parameters:

  • catalogs (Hash)

    { :to => OctocatalogDiff::Catalog, :from => OctocatalogDiff::Catalog }

Returns:

  • (Array<diffs>)

    Array of diffs


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

def diffs(catalogs)
  @logger.debug 'Begin compute diffs between catalogs'
  diff_opts = @options.merge(logger: @logger)

  # Construct the actual differ object that the present one wraps
  differ = OctocatalogDiff::CatalogDiff::Differ.new(diff_opts, catalogs[:from], catalogs[:to])
  differ.ignore(attr: 'tags') unless @options.fetch(:include_tags, false)
  differ.ignore(@options.fetch(:ignore, []))
  differ.ignore_tags

  # Actually perform the diff
  diff_result = differ.diff
  @logger.debug 'Success compute diffs between catalogs'
  diff_result
end