lib/berkshelf/source.rb in berkshelf-3.0.0.beta4 vs lib/berkshelf/source.rb in berkshelf-3.0.0.beta5

- old
+ new

@@ -1,5 +1,7 @@ +require 'berkshelf/api-client' + module Berkshelf class Source include Comparable # @return [Berkshelf::SourceURI] @@ -7,14 +9,32 @@ # @param [String, Berkshelf::SourceURI] uri def initialize(uri) @uri = SourceURI.parse(uri) @api_client = APIClient.new(uri) + @universe = nil end - # @return [Hash] + # Forcefully obtain the universe from the API endpoint and assign it to {#universe}. This + # will reload the value of {#universe} even if it has been loaded before. + # + # @return [Array<APIClient::RemoteCookbook>] + def build_universe + @universe = api_client.universe + rescue => ex + @universe = Array.new + raise ex + end + + # Return the universe from the API endpoint. + # + # This is lazily loaded so the universe will be retrieved from the API endpoint on the first + # call and cached for future calls. Send the {#build_universe} message if you want to reload + # the cached universe. + # + # @return [Array<APIClient::RemoteCookbook>] def universe - @universe ||= api_client.universe + @universe || build_universe end # @param [String] name # @param [String] version #