class Minimart::Web::Cookbooks
Given a path to the inventory directory, this class will generate the necessary JSON output to power the main dashboard, and return cookbooks in a format that can be used to build the various web pages.
Constants
- FILE_NAME
Attributes
data_structure[R]
inventory_directory[R]
@return [String] The path to the cookbook inventory
Public Class Methods
new(opts)
click to toggle source
@param [Hash] opts @option opts [String] :inventory_directory The path to the cookbook inventory
# File lib/minimart/web/cookbooks.rb, line 23 def initialize(opts) @inventory_directory = opts[:inventory_directory] @data_structure = {} generate end
Public Instance Methods
add(cookbook)
click to toggle source
Add a cookbook to the data structure. @param [Minimart::Cookbook] cookbook The cookbook to add
# File lib/minimart/web/cookbooks.rb, line 48 def add(cookbook) data_structure[cookbook.name] ||= [] data_structure[cookbook.name] << cookbook end
individual_cookbooks()
click to toggle source
Get a non-nested version of the cookbooks structure
# File lib/minimart/web/cookbooks.rb, line 42 def individual_cookbooks values.flatten end
to_json()
click to toggle source
Get a JSON representation of the most recent version of each cookbook found in the inventory_directory. @return [Hash]
# File lib/minimart/web/cookbooks.rb, line 33 def to_json map do |cookbook_name, cookbook_versions| cookbook_versions.first.to_hash.merge(available_versions: cookbook_versions.size) end.to_json end
Private Instance Methods
build_data_structure()
click to toggle source
# File lib/minimart/web/cookbooks.rb, line 62 def build_data_structure cookbooks.each { |cookbook| add(cookbook) } end
cookbooks()
click to toggle source
# File lib/minimart/web/cookbooks.rb, line 73 def cookbooks inventory_cookbook_paths.map { |path| Minimart::Cookbook.from_path(path) } end
generate()
click to toggle source
# File lib/minimart/web/cookbooks.rb, line 57 def generate build_data_structure sort_data end
inventory_cookbook_paths()
click to toggle source
# File lib/minimart/web/cookbooks.rb, line 77 def inventory_cookbook_paths Utils::FileHelper.find_cookbooks_in_directory(inventory_directory) end
sort_data()
click to toggle source
Sort cookbooks in version desc order
# File lib/minimart/web/cookbooks.rb, line 67 def sort_data data_structure.values.map! do |versions| versions.sort!.reverse! end end