class Minimart::Cookbook
An object wrapper to get information about a cookbook.
Attributes
Public Class Methods
Generate a new Minimart::Cookbook
from a path @param [String] path The path to the cookbook directory @return [Minimart::Cookbook]
# File lib/minimart/cookbook.rb, line 17 def self.from_path(path) path = Minimart::Utils::FileHelper.cookbook_path_in_directory(path) new (Ridley::Chef::Cookbook.from_path(path)) end
@param [Ridley::Chef::Cookbook] raw_cookbook
# File lib/minimart/cookbook.rb, line 23 def initialize(raw_cookbook) @raw_cookbook = raw_cookbook end
Public Instance Methods
# File lib/minimart/cookbook.rb, line 150 def <=>(other) Semverse::Version.new(version) <=> Semverse::Version.new(other.version) end
Get the parsed Markdown content of the CHANGELOG @return [String]
# File lib/minimart/cookbook.rb, line 113 def changelog_content @changelog_content ||= Web::MarkdownParser.parse(changelog_file) if changelog_file end
Get the path to the CHANGELOG file if one is available @return [String]
# File lib/minimart/cookbook.rb, line 101 def changelog_file @changelog_file ||= find_file('changelog') end
Get any dependencies that this cookbook may have @return [Hash] cookbook_name => version_requirement
# File lib/minimart/cookbook.rb, line 83 def dependencies metadata.dependencies end
Get a short description of the cookbook. @return [String]
# File lib/minimart/cookbook.rb, line 47 def description metadata.description end
Get a human friendly downlaod date of this cookbook (ex. January 1st, 2015) @return [String]
# File lib/minimart/cookbook.rb, line 145 def download_date return unless downloaded_at downloaded_at.strftime('%B %d, %Y') end
Get any metadata about how this cookbook was downloaded. @return [Minimart::Mirror::DownloadMetadata]
# File lib/minimart/cookbook.rb, line 169 def download_metadata @download_metadata ||= Minimart::Mirror::DownloadMetadata.new(self.path) end
Get the time at which this cookbook was downloaded by Minimart
. @return [Time]
# File lib/minimart/cookbook.rb, line 139 def downloaded_at download_metadata.downloaded_at end
Get the issues url of the cookbook @return [String]
# File lib/minimart/cookbook.rb, line 65 def issues_url metadata.issues_url end
Get the maintainer of the cookbook @return [String]
# File lib/minimart/cookbook.rb, line 53 def maintainer metadata.maintainer end
Get the name of the cookbook @return [String]
# File lib/minimart/cookbook.rb, line 29 def name raw_cookbook.cookbook_name end
# File lib/minimart/cookbook.rb, line 158 def normalized_platforms return {'question' => 'Not Specified'} if platforms.nil? || platforms.empty? platforms.inject({}) do |memo, platform| memo[platform_icon(platform)] = platform.capitalize memo end end
Get the path to the cookbook on the file system @return [String]
# File lib/minimart/cookbook.rb, line 71 def path raw_cookbook.path end
Get a list of platforms this cookbook can run on @return [Array<String>]
# File lib/minimart/cookbook.rb, line 89 def platforms metadata.platforms.keys end
Get the parsed Markdown content of the README @return [String]
# File lib/minimart/cookbook.rb, line 107 def readme_content @readme_content ||= Web::MarkdownParser.parse(readme_file) if readme_file end
Get the path to the README file if one is available @return [String]
# File lib/minimart/cookbook.rb, line 95 def readme_file @readme_file ||= find_file('readme') end
# File lib/minimart/cookbook.rb, line 154 def satisfies_requirement?(constraint) Semverse::Constraint.new(constraint).satisfies?(version) end
Get the source url of the cookbook @return [String]
# File lib/minimart/cookbook.rb, line 59 def source_url metadata.source_url end
# File lib/minimart/cookbook.rb, line 117 def to_hash { name: name, version: version, description: description, maintainer: maintainer, download_url: cookbook_download_path(self), url: cookbook_path(self), downloaded_at: downloaded_at, download_date: download_date, platforms: normalized_platforms, source_url: source_url, issues_url: issues_url } end
# File lib/minimart/cookbook.rb, line 133 def to_json(opts = {}) to_hash.to_json end
Return a the cookbook name, and version number separated by a dash @return [String]
# File lib/minimart/cookbook.rb, line 41 def to_s raw_cookbook.name end
Get the version of the cookbook @return [String]
# File lib/minimart/cookbook.rb, line 35 def version raw_cookbook.version end
Get a URL friendly version of the cookbook version @return [String]
# File lib/minimart/cookbook.rb, line 77 def web_friendly_version version.gsub('.', '_') end
Protected Instance Methods
# File lib/minimart/cookbook.rb, line 181 def find_file(name) Dir.glob(File.join(path, '*')).find do |file| File.basename(file, File.extname(file)) =~ /\A#{name}\z/i end end
# File lib/minimart/cookbook.rb, line 177 def metadata raw_cookbook.metadata end