Class: Berkshelf::Formatters::JSON
- Inherits:
-
Object
- Object
- Berkshelf::Formatters::JSON
- Includes:
- AbstractFormatter
- Defined in:
- lib/berkshelf/formatters/json.rb
Instance Method Summary collapse
- #cleanup_hook ⇒ Object
-
#error(message) ⇒ Object
Add an error message entry to delayed output.
-
#initialize ⇒ JSON
constructor
A new instance of JSON.
-
#install(cookbook, version, location) ⇒ Object
Add a Cookbook installation entry to delayed output.
-
#msg(message) ⇒ Object
Add a generic message entry to delayed output.
-
#package(cookbook, destination) ⇒ Object
Add a Cookbook package entry to delayed output.
-
#show(cookbook) ⇒ Object
Output Cookbook info entry to delayed output.
-
#upload(cookbook, version, chef_api_url) ⇒ Object
Add a Cookbook upload entry to delayed output.
-
#use(cookbook, version, location = nil) ⇒ Object
Add a Cookbook use entry to delayed output.
Constructor Details
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 print ::JSON.pretty_generate(output) end |
#error(message) ⇒ Object
Add an error message entry to delayed output
92 93 94 |
# File 'lib/berkshelf/formatters/json.rb', line 92 def error() output[:errors] << end |
#install(cookbook, version, location) ⇒ Object
Add a Cookbook installation entry to delayed output
34 35 36 37 38 |
# File 'lib/berkshelf/formatters/json.rb', line 34 def install(cookbook, version, location) cookbooks[cookbook] ||= {} cookbooks[cookbook][:version] = version cookbooks[cookbook][:location] = location.to_s end |
#msg(message) ⇒ Object
Add a generic message entry to delayed output
85 86 87 |
# File 'lib/berkshelf/formatters/json.rb', line 85 def msg() output[:messages] << end |
#package(cookbook, destination) ⇒ Object
Add a Cookbook package entry to delayed output
70 71 72 73 |
# File 'lib/berkshelf/formatters/json.rb', line 70 def package(cookbook, destination) cookbooks[cookbook] ||= {} cookbooks[cookbook][:destination] = destination end |
#show(cookbook) ⇒ Object
Output Cookbook info entry to delayed output
78 79 80 |
# File 'lib/berkshelf/formatters/json.rb', line 78 def show(cookbook) cookbooks[cookbook.cookbook_name] = cookbook.pretty_hash end |
#upload(cookbook, version, chef_api_url) ⇒ Object
Add a Cookbook upload entry to delayed output
60 61 62 63 64 |
# File 'lib/berkshelf/formatters/json.rb', line 60 def upload(cookbook, version, chef_api_url) cookbooks[cookbook] ||= {} cookbooks[cookbook][:version] = version cookbooks[cookbook][:uploaded_to] = chef_api_url end |
#use(cookbook, version, location = nil) ⇒ Object
Add a Cookbook use entry to delayed output
45 46 47 48 49 50 51 52 53 |
# File 'lib/berkshelf/formatters/json.rb', line 45 def use(cookbook, version, location = nil) cookbooks[cookbook] ||= {} cookbooks[cookbook][:version] = version if location && location.is_a?(PathLocation) cookbooks[cookbook][:metadata] = true if location. cookbooks[cookbook][:location] = location.relative_path end end |