class Minimart::Cookbook

An object wrapper to get information about a cookbook.

Attributes

raw_cookbook[R]

Public Class Methods

from_path(path) click to toggle source

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
new(raw_cookbook) click to toggle source

@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

<=>(other) click to toggle source
# File lib/minimart/cookbook.rb, line 150
def <=>(other)
  Semverse::Version.new(version) <=> Semverse::Version.new(other.version)
end
changelog_content() click to toggle source

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
changelog_file() click to toggle source

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
dependencies() click to toggle source

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
description() click to toggle source

Get a short description of the cookbook. @return [String]

# File lib/minimart/cookbook.rb, line 47
def description
  metadata.description
end
download_date() click to toggle source

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
download_metadata() click to toggle source

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
downloaded_at() click to toggle source

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
issues_url() click to toggle source

Get the issues url of the cookbook @return [String]

# File lib/minimart/cookbook.rb, line 65
def issues_url
  metadata.issues_url
end
maintainer() click to toggle source

Get the maintainer of the cookbook @return [String]

# File lib/minimart/cookbook.rb, line 53
def maintainer
  metadata.maintainer
end
name() click to toggle source

Get the name of the cookbook @return [String]

# File lib/minimart/cookbook.rb, line 29
def name
  raw_cookbook.cookbook_name
end
normalized_platforms() click to toggle source
# 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
path() click to toggle source

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
platforms() click to toggle source

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
readme_content() click to toggle source

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
readme_file() click to toggle source

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
satisfies_requirement?(constraint) click to toggle source
# File lib/minimart/cookbook.rb, line 154
def satisfies_requirement?(constraint)
  Semverse::Constraint.new(constraint).satisfies?(version)
end
source_url() click to toggle source

Get the source url of the cookbook @return [String]

# File lib/minimart/cookbook.rb, line 59
def source_url
  metadata.source_url
end
to_hash() click to toggle source
# 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
to_json(opts = {}) click to toggle source
# File lib/minimart/cookbook.rb, line 133
def to_json(opts = {})
  to_hash.to_json
end
to_s() click to toggle source

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
version() click to toggle source

Get the version of the cookbook @return [String]

# File lib/minimart/cookbook.rb, line 35
def version
  raw_cookbook.version
end
web_friendly_version() click to toggle source

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

find_file(name) click to toggle source
# 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
metadata() click to toggle source
# File lib/minimart/cookbook.rb, line 177
def metadata
  raw_cookbook.metadata
end