Class: Berkshelf::Formatters::JSON
- Inherits:
-
Object
- Object
- Berkshelf::Formatters::JSON
- Includes:
- AbstractFormatter
- Defined in:
- lib/berkshelf/formatters/json.rb
Overview
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.
-
#upload(cookbook, version, chef_api_url) ⇒ Object
Add a Cookbook upload entry to delayed output.
-
#use(cookbook, version, path = nil) ⇒ Object
Add a Cookbook use entry to delayed output.
Constructor Details
#initialize ⇒ JSON
Returns a new instance of JSON.
9 10 11 12 13 14 15 16 17 |
# File 'lib/berkshelf/formatters/json.rb', line 9 def initialize @output = { cookbooks: Array.new, errors: Array.new, messages: Array.new } @cookbooks = Hash.new super end |
Instance Method Details
#cleanup_hook ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/berkshelf/formatters/json.rb', line 19 def cleanup_hook cookbooks.each do |name, details| details[:name] = name output[:cookbooks] << details end print MultiJson.dump(output) end |
#error(message) ⇒ Object
Add an error message entry to delayed output
71 72 73 |
# File 'lib/berkshelf/formatters/json.rb', line 71 def error() output[:errors] << end |
#install(cookbook, version, location) ⇒ Object
Add a Cookbook installation entry to delayed output
33 34 35 36 37 |
# File 'lib/berkshelf/formatters/json.rb', line 33 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
64 65 66 |
# File 'lib/berkshelf/formatters/json.rb', line 64 def msg() output[:messages] << end |
#upload(cookbook, version, chef_api_url) ⇒ Object
Add a Cookbook upload entry to delayed output
55 56 57 58 59 |
# File 'lib/berkshelf/formatters/json.rb', line 55 def upload(cookbook, version, chef_api_url) cookbooks[cookbook] ||= {} cookbooks[cookbook][:version] = version cookbooks[cookbook][:uploaded_to] = chef_api_url end |
#use(cookbook, version, path = nil) ⇒ Object
Add a Cookbook use entry to delayed output
44 45 46 47 48 |
# File 'lib/berkshelf/formatters/json.rb', line 44 def use(cookbook, version, path = nil) cookbooks[cookbook] ||= {} cookbooks[cookbook][:version] = version cookbooks[cookbook][:location] = path if path end |