Class: Berkshelf::Formatters::JSON

Inherits:
Object
  • Object
show all
Includes:
AbstractFormatter
Defined in:
lib/berkshelf/formatters/json.rb

Overview

Author:

Instance Method Summary collapse

Constructor Details

#initializeJSON

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_hookObject



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

Parameters:



71
72
73
# File 'lib/berkshelf/formatters/json.rb', line 71

def error(message)
  output[:errors] << message
end

#install(cookbook, version, location) ⇒ Object

Add a Cookbook installation entry to delayed output

Parameters:



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

Parameters:



64
65
66
# File 'lib/berkshelf/formatters/json.rb', line 64

def msg(message)
  output[:messages] << message
end

#upload(cookbook, version, chef_api_url) ⇒ Object

Add a Cookbook upload entry to delayed output

Parameters:



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

Parameters:



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