lib/berkshelf/cached_cookbook.rb in berkshelf-2.0.0.beta vs lib/berkshelf/cached_cookbook.rb in berkshelf-2.0.0

- old
+ new

@@ -1,7 +1,6 @@ module Berkshelf - # @author Jamie Winsor <reset@riotgames.com> class CachedCookbook < Ridley::Chef::Cookbook class << self # @param [#to_s] path # a path on disk to the location of a Cookbook downloaded by the Downloader # @@ -33,9 +32,26 @@ a.push " Email: #{metadata.maintainer_email}" unless metadata.maintainer_email.blank? a.push " License: #{metadata.license}" unless metadata.license.blank? a.push " Platforms: #{pretty_map(metadata.platforms, 14)}" unless metadata.platforms.blank? a.push "Dependencies: #{pretty_map(dependencies, 14)}" unless dependencies.blank? end.join("\n") + end + + def pretty_json + pretty_hash.to_json + end + + def pretty_hash + {}.tap do |h| + h[:name] = cookbook_name unless name.blank? + h[:version] = version unless version.blank? + h[:description] = metadata.description unless metadata.description.blank? + h[:author] = metadata.maintainer unless metadata.maintainer.blank? + h[:email] = metadata.maintainer_email unless metadata.maintainer_email.blank? + h[:license] = metadata.license unless metadata.license.blank? + h[:platforms] = metadata.platforms.to_hash unless metadata.platforms.blank? + h[:dependencies] = dependencies.to_hash unless dependencies.blank? + end end private def pretty_map(hash, padding) hash.map { |k,v| "#{k} (#{v})" }.join("\n" + ' '*padding)