Class: Berkshelf::JsonFormatter
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- Berkshelf::JsonFormatter
- Defined in:
- lib/berkshelf/formatters/json.rb
Instance Method Summary collapse
- #cleanup_hook ⇒ Object
- #deprecation(message) ⇒ Object
-
#error(message) ⇒ Object
Add an error message entry to delayed output.
- #fetch(dependency) ⇒ Object
-
#info(cookbook) ⇒ Object
Output Cookbook info entry to delayed output.
-
#initialize ⇒ JsonFormatter
constructor
A new instance of JsonFormatter.
-
#install(source, cookbook) ⇒ Object
Add a Cookbook installation entry to delayed output.
-
#list(dependencies) ⇒ Object
Output a list of cookbooks to delayed output.
-
#msg(message) ⇒ Object
Add a generic message entry to delayed output.
-
#outdated(hash) ⇒ Object
Output a list of outdated cookbooks and the most recent version to delayed output.
-
#package(destination) ⇒ Object
Output a package message using.
-
#search(results) ⇒ Object
Ouput Cookbook search results to delayed output.
-
#show(cookbook) ⇒ Object
Output Cookbook path entry to delayed output.
-
#skipping(cookbook, conn) ⇒ Object
Add a Cookbook skip entry to delayed output.
-
#uploaded(cookbook, conn) ⇒ Object
Add a Cookbook upload entry to delayed output.
-
#use(dependency) ⇒ Object
Add a Cookbook use entry to delayed output.
-
#vendor(cookbook, destination) ⇒ Object
Add a vendor message to delayed output.
-
#version ⇒ Object
Output the version of Berkshelf.
-
#warn(message) ⇒ Object
Add a warning message entry to delayed output.
Methods inherited from BaseFormatter
Constructor Details
#initialize ⇒ JsonFormatter
Returns a new instance of JsonFormatter.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/berkshelf/formatters/json.rb', line 8 def initialize @output = { cookbooks: [], errors: [], messages: [], warnings: [], } @cookbooks = {} Berkshelf.ui.mute { super } end |
Instance Method Details
#cleanup_hook ⇒ Object
20 21 22 23 24 25 26 27 |
# 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 |
#deprecation(message) ⇒ Object
182 183 184 |
# File 'lib/berkshelf/formatters/json.rb', line 182 def deprecation() output[:warnings] << "DEPRECATED: #{}" end |
#error(message) ⇒ Object
Add an error message entry to delayed output
171 172 173 |
# File 'lib/berkshelf/formatters/json.rb', line 171 def error() output[:errors] << end |
#fetch(dependency) ⇒ Object
30 31 32 33 34 |
# 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 |
#info(cookbook) ⇒ Object
Output Cookbook info entry to delayed output.
109 110 111 112 |
# File 'lib/berkshelf/formatters/json.rb', line 109 def info(cookbook) path = File.(cookbook.path) cookbooks[cookbook.cookbook_name] = { path: path } end |
#install(source, cookbook) ⇒ Object
Add a Cookbook installation entry to delayed output
42 43 44 45 46 47 48 49 50 |
# 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 |
#list(dependencies) ⇒ Object
Output a list of cookbooks to delayed output
124 125 126 127 128 129 130 131 132 |
# 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 |
#msg(message) ⇒ Object
Add a generic message entry to delayed output
164 165 166 |
# File 'lib/berkshelf/formatters/json.rb', line 164 def msg() output[:messages] << end |
#outdated(hash) ⇒ Object
Output a list of outdated cookbooks and the most recent version to delayed output
93 94 95 96 97 98 99 100 101 102 103 104 |
# 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 |
#package(destination) ⇒ Object
Output a package message using
117 118 119 |
# File 'lib/berkshelf/formatters/json.rb', line 117 def package(destination) output[:messages] << "Cookbook(s) packaged to #{destination}" end |
#search(results) ⇒ Object
Ouput Cookbook search results to delayed output
145 146 147 148 149 150 |
# 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 |
#show(cookbook) ⇒ Object
Output Cookbook path entry to delayed output
137 138 139 140 |
# File 'lib/berkshelf/formatters/json.rb', line 137 def show(cookbook) path = File.(cookbook.path) cookbooks[cookbook.cookbook_name] = { path: path } end |
#skipping(cookbook, conn) ⇒ Object
Add a Cookbook skip entry to delayed output
80 81 82 83 84 85 |
# 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 |
#uploaded(cookbook, conn) ⇒ Object
Add a Cookbook upload entry to delayed output
69 70 71 72 73 74 |
# 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 |
#use(dependency) ⇒ Object
Add a Cookbook use entry to delayed output
55 56 57 58 59 60 61 62 63 |
# 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. cookbooks[dependency.name][:location] = dependency.location.relative_path end end |
#vendor(cookbook, destination) ⇒ Object
Add a vendor message to delayed output
156 157 158 159 |
# 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 |
#version ⇒ Object
Output the version of Berkshelf
4 5 6 |
# File 'lib/berkshelf/formatters/json.rb', line 4 def version @output = { version: Berkshelf::VERSION } end |
#warn(message) ⇒ Object
Add a warning message entry to delayed output
178 179 180 |
# File 'lib/berkshelf/formatters/json.rb', line 178 def warn() output[:warnings] << end |