lib/berkshelf/formatters/json.rb in berkshelf-3.0.0.beta1 vs lib/berkshelf/formatters/json.rb in berkshelf-3.0.0.beta2

- old
+ new

@@ -3,10 +3,15 @@ class JSON include AbstractFormatter register_formatter :json + # Output the version of Berkshelf + def version + @output = { version: Berkshelf::VERSION } + end + def initialize @output = { cookbooks: Array.new, errors: Array.new, messages: Array.new @@ -20,11 +25,11 @@ cookbooks.each do |name, details| details[:name] = name output[:cookbooks] << details end - print ::JSON.pretty_generate(output) + puts ::JSON.pretty_generate(output) end # @param [Berkshelf::Dependency] dependency def fetch(dependency) cookbooks[dependency] ||= {} @@ -62,19 +67,47 @@ end end # Add a Cookbook upload entry to delayed output # - # @param [String] cookbook - # @param [String] version - # @param [String] chef_api_url - def upload(cookbook, version, chef_api_url) - cookbooks[cookbook] ||= {} - cookbooks[cookbook][:version] = version - cookbooks[cookbook][:uploaded_to] = chef_api_url + # @param [Berkshelf::CachedCookbook] cookbook + # @param [Ridley::Connection] conn + def upload(cookbook, conn) + name = cookbook.cookbook_name + cookbooks[name] ||= {} + cookbooks[name][:version] = cookbook.version + cookbooks[name][:uploaded_to] = conn.server_url end + # Add a Cookbook skip entry to delayed output + # + # @param [Berkshelf::CachedCookbook] cookbook + # @param [Ridley::Connection] conn + def skip(cookbook, conn) + name = cookbook.cookbook_name + cookbooks[name] ||= {} + cookbooks[name][:version] = cookbook.version + cookbooks[name][:skipped] = true + end + + # Output a list of outdated cookbooks and the most recent version + # to delayed output + # + # @param [Hash] hash + # the list of outdated cookbooks in the format + # { 'cookbook' => { 'api.berkshelf.com' => #<Cookbook> } } + def outdated(hash) + hash.keys.each do |name| + hash[name].each do |source, cookbook| + cookbooks[name] ||= {} + cookbooks[name][:version] = cookbook.version + cookbooks[name][:sources] ||= {} + cookbooks[name][:sources][source] = cookbook + end + end + end + # Add a Cookbook package entry to delayed output # # @param [String] cookbook # @param [String] destination def package(cookbook, destination) @@ -85,9 +118,18 @@ # Output Cookbook info entry to delayed output # # @param [CachedCookbook] cookbook def show(cookbook) cookbooks[cookbook.cookbook_name] = cookbook.pretty_hash + end + + # Add a vendor message to delayed output + # + # @param [CachedCookbook] cookbook + # @param [String] destination + def vendor(cookbook, destination) + cookbook_destination = File.join(destination, cookbook.cookbook_name) + msg("Vendoring #{cookbook.cookbook_name} (#{cookbook.version}) to #{cookbook_destination}") end # Add a generic message entry to delayed output # # @param [String] message