class ChefCLI::Policyfile::CommunityCookbookSource

def ==(other)

def ==(other)
  other.is_a?(self.class) && other.uri == uri && other.preferred_cookbooks == preferred_cookbooks
end

def default_source_args

def default_source_args
  [:supermarket, uri]
end

def desc

def desc
  "supermarket(#{uri})"
end

def full_community_graph

def full_community_graph
  @full_community_graph ||=
    begin
      graph_json = http_connection_for(uri).get("/universe")
      JSON.parse(graph_json)
    end
end

def http_connection_for(base_url)

def http_connection_for(base_url)
  @http_connections[base_url] ||= Chef::HTTP::Simple.new(base_url)
end

def initialize(uri = nil)

def initialize(uri = nil)
  @uri = uri || "https://supermarket.chef.io"
  @http_connections = {}
  @preferred_cookbooks = []
  yield self if block_given?
end

def null?

def null?
  false
end

def preferred_for(*cookbook_names)

def preferred_for(*cookbook_names)
  preferred_cookbooks.concat(cookbook_names)
end

def preferred_source_for?(cookbook_name)

def preferred_source_for?(cookbook_name)
  preferred_cookbooks.include?(cookbook_name)
end

def source_options_for(cookbook_name, cookbook_version)

def source_options_for(cookbook_name, cookbook_version)
  base_uri = full_community_graph[cookbook_name][cookbook_version]["download_url"]
  { artifactserver: base_uri, version: cookbook_version }
end

def universe_graph

def universe_graph
  @universe_graph ||= begin
    full_community_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)|
      normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)|
        deps_by_version[version] = metadata["dependencies"]
        deps_by_version
      end
      normalized_graph
    end
  end
end