class ChefDK::CookbookSourceConflict

Attributes

conflicting_cookbooks[R]
cookbook_sources[R]

Public Class Methods

new(conflicting_cookbooks, cookbook_sources) click to toggle source
Calls superclass method
# File lib/chef-dk/exceptions.rb, line 110
def initialize(conflicting_cookbooks, cookbook_sources)
  @conflicting_cookbooks = conflicting_cookbooks
  @cookbook_sources      = cookbook_sources
  super(compute_message)
end

Private Instance Methods

compute_message() click to toggle source
# File lib/chef-dk/exceptions.rb, line 118
def compute_message
  conflicting_cookbook_sets = cookbook_sources.combination(2).map do |source_a, source_b|
    overlapping_cookbooks = conflicting_cookbooks.select do |cookbook_name|
      source_a.universe_graph.key?(cookbook_name) && source_b.universe_graph.key?(cookbook_name)
    end
    "Source #{source_a.desc} and #{source_b.desc} contain conflicting cookbooks:\n" +
      overlapping_cookbooks.sort.map { |c| "- #{c}" }.join("\n") + "\n\n" +
      resolution_message(overlapping_cookbooks)
  end
  conflicting_cookbook_sets.join("\n")
end
resolution_message(overlapping_cookbooks) click to toggle source
# File lib/chef-dk/exceptions.rb, line 130
    def resolution_message(overlapping_cookbooks)
      example_source       = cookbook_sources.first
      source_key, location = example_source.default_source_args
      <<~EXAMPLE
        You can set a preferred source to resolve this issue with code like:

        default_source :#{source_key}, "#{location}" do |s|
          s.preferred_for "#{overlapping_cookbooks.join('", "')}"
        end
      EXAMPLE
    end