Class: Berkshelf::CachedCookbook

Inherits:
Ridley::Chef::Cookbook
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/berkshelf/cached_cookbook.rb

Constant Summary collapse

DIRNAME_REGEXP =
/^(.+)-(.+)$/.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_store_path(path) ⇒ CachedCookbook

Returns an instance of CachedCookbook initialized by the contents found at the given path.

Parameters:

  • path (#to_s)

    a path on disk to the location of a Cookbook downloaded by the Downloader

Returns:

  • (CachedCookbook)

    an instance of CachedCookbook initialized by the contents found at the given path.



10
11
12
13
14
15
16
# File 'lib/berkshelf/cached_cookbook.rb', line 10

def from_store_path(path)
  path        = Pathname.new(path)
  cached_name = File.basename(path.to_s).slice(DIRNAME_REGEXP, 1)
  return nil if cached_name.nil?

  loaded_cookbooks[path.to_s] ||= from_path(path)
end

Instance Method Details

#dependenciesHash

Returns:

  • (Hash)


36
37
38
# File 'lib/berkshelf/cached_cookbook.rb', line 36

def dependencies
  .recommendations.merge(.dependencies)
end

#pretty_hashHash

High-level information about this cached cookbook in Hash format

Returns:

  • (Hash)


63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/berkshelf/cached_cookbook.rb', line 63

def pretty_hash
  {}.tap do |h|
    h[:name]          = cookbook_name unless cookbook_name.blank?
    h[:version]       = version unless version.blank?
    h[:description]   = description unless description.blank?
    h[:author]        = maintainer unless maintainer.blank?
    h[:email]         = maintainer_email unless maintainer_email.blank?
    h[:license]       = license unless license.blank?
    h[:platforms]     = platforms.to_hash unless platforms.blank?
    h[:dependencies]  = dependencies.to_hash unless dependencies.blank?
  end
end

#pretty_jsonString

High-level information about this cached cookbook in JSON format

Returns:



56
57
58
# File 'lib/berkshelf/cached_cookbook.rb', line 56

def pretty_json
  JSON.pretty_generate(pretty_hash)
end

#pretty_printObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/berkshelf/cached_cookbook.rb', line 40

def pretty_print
  [].tap do |a|
    a.push "        Name: #{cookbook_name}" unless name.blank?
    a.push "     Version: #{version}" unless version.blank?
    a.push " Description: #{.description}" unless .description.blank?
    a.push "      Author: #{.maintainer}" unless .maintainer.blank?
    a.push "       Email: #{.maintainer_email}" unless .maintainer_email.blank?
    a.push "     License: #{.license}" unless .license.blank?
    a.push "   Platforms: #{pretty_map(.platforms, 14)}" unless .platforms.blank?
    a.push "Dependencies: #{pretty_map(dependencies, 14)}" unless dependencies.blank?
  end.join("\n")
end