class Berkshelf::JsonFormatter
Attributes
Public Class Methods
Source
# File lib/berkshelf/formatters/json.rb, line 8 def initialize @output = { cookbooks: [], errors: [], messages: [], warnings: [], } @cookbooks = {} Berkshelf.ui.mute { super } end
Public Instance Methods
Source
# File lib/berkshelf/formatters/json.rb, line 20 def cleanup_hook cookbooks.each do |name, details| details[:name] = name output[:cookbooks] << details end puts ::JSON.pretty_generate(output) end
Source
# File lib/berkshelf/formatters/json.rb, line 182 def deprecation(message) output[:warnings] << "DEPRECATED: #{message}" end
Source
# File lib/berkshelf/formatters/json.rb, line 171 def error(message) output[:errors] << message end
Add an error message entry to delayed output
@param [String] message
Source
# File lib/berkshelf/formatters/json.rb, line 30 def fetch(dependency) cookbooks[dependency] ||= {} cookbooks[dependency][:version] = dependency.locked_version.to_s cookbooks[dependency][:location] = dependency.location end
@param [Berkshelf::Dependency] dependency
Source
# File lib/berkshelf/formatters/json.rb, line 109 def info(cookbook) path = File.expand_path(cookbook.path) cookbooks[cookbook.cookbook_name] = { path: path } end
Output Cookbook info entry to delayed output.
@param [CachedCookbook] cookbook
Source
# File lib/berkshelf/formatters/json.rb, line 42 def install(source, cookbook) cookbooks[cookbook.name] ||= {} cookbooks[cookbook.name][:version] = cookbook.version unless source.default? cookbooks[cookbook.name][:api_source] = source.uri cookbooks[cookbook.name][:location_path] = cookbook.location_path end end
Add a Cookbook installation entry to delayed output
@param [Source] source
the source the dependency is being downloaded from
@param [RemoteCookbook] cookbook
the cookbook to be downloaded
Source
# File lib/berkshelf/formatters/json.rb, line 124 def list(dependencies) dependencies.each do |dependency, cookbook| cookbooks[dependency.name] ||= {} cookbooks[dependency.name][:version] = dependency.locked_version.to_s if dependency.location cookbooks[dependency.name][:location] = dependency.location end end end
Output a list of cookbooks to delayed output
@param [Array<Dependency>] dependencies
Source
# File lib/berkshelf/formatters/json.rb, line 164 def msg(message) output[:messages] << message end
Add a generic message entry to delayed output
@param [String] message
Source
# File lib/berkshelf/formatters/json.rb, line 93 def outdated(hash) hash.each do |name, info| info["remote"].each do |remote_source, remote_version| source = remote_source.uri.to_s cookbooks[name] ||= {} cookbooks[name][:local] = info["local"].to_s cookbooks[name][:remote] ||= {} cookbooks[name][:remote][source] = remote_version.to_s end end 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' => { 'supermarket.chef.io' => #<Cookbook> } }
Source
# File lib/berkshelf/formatters/json.rb, line 117 def package(destination) output[:messages] << "Cookbook(s) packaged to #{destination}" end
Output a package message using
@param [String] destination
Source
# File lib/berkshelf/formatters/json.rb, line 145 def search(results) results.sort_by(&:name).each do |remote_cookbook| cookbooks[remote_cookbook.name] ||= {} cookbooks[remote_cookbook.name][:version] = remote_cookbook.version end end
Ouput Cookbook search results to delayed output
@param [Array<APIClient::RemoteCookbook>] results
Source
# File lib/berkshelf/formatters/json.rb, line 137 def show(cookbook) path = File.expand_path(cookbook.path) cookbooks[cookbook.cookbook_name] = { path: path } end
Output Cookbook path entry to delayed output
@param [CachedCookbook] cookbook
Source
# File lib/berkshelf/formatters/json.rb, line 80 def skipping(cookbook, conn) name = cookbook.cookbook_name cookbooks[name] ||= {} cookbooks[name][:version] = cookbook.version cookbooks[name][:skipped] = true end
Add a Cookbook skip entry to delayed output
@param [Berkshelf::CachedCookbook] cookbook @param [Ridley::Connection] conn
Source
# File lib/berkshelf/formatters/json.rb, line 69 def uploaded(cookbook, conn) name = cookbook.cookbook_name cookbooks[name] ||= {} cookbooks[name][:version] = cookbook.version cookbooks[name][:uploaded_to] = conn.server_url end
Add a Cookbook upload entry to delayed output
@param [Berkshelf::CachedCookbook] cookbook @param [Ridley::Connection] conn
Source
# File lib/berkshelf/formatters/json.rb, line 55 def use(dependency) cookbooks[dependency.name] ||= {} cookbooks[dependency.name][:version] = dependency.cached_cookbook.version if dependency.location.is_a?(PathLocation) cookbooks[dependency.name][:metadata] = true if dependency.location.metadata? cookbooks[dependency.name][:location] = dependency.location.relative_path end end
Add a Cookbook use entry to delayed output
@param [Dependency] dependency
Source
# File lib/berkshelf/formatters/json.rb, line 156 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 vendor message to delayed output
@param [CachedCookbook] cookbook @param [String] destination
Source
# File lib/berkshelf/formatters/json.rb, line 4 def version @output = { version: Berkshelf::VERSION } end
Output the version of Berkshelf
Source
# File lib/berkshelf/formatters/json.rb, line 178 def warn(message) output[:warnings] << message end
Add a warning message entry to delayed output
@param [String] message