Class: Berkshelf::CachedCookbook

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

Constant Summary collapse

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

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.



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

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[path.to_s] ||= from_path(path, name: cached_name)
end

Instance Method Details

#dependenciesHash

Returns:

  • (Hash)


24
25
26
# File 'lib/berkshelf/cached_cookbook.rb', line 24

def dependencies
  .recommendations.merge(.dependencies)
end

#pretty_hashObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/berkshelf/cached_cookbook.rb', line 45

def pretty_hash
  {}.tap do |h|
    h[:name]          = cookbook_name unless 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_jsonObject



41
42
43
# File 'lib/berkshelf/cached_cookbook.rb', line 41

def pretty_json
  pretty_hash.to_json
end

#pretty_printObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/berkshelf/cached_cookbook.rb', line 28

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