Class: ChefDK::PolicyfileLock::CachedCookbook

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-dk/policyfile_lock.rb

Overview

CachedCookbook objects represent a cookbook that has been fetched from an upstream canonical source and stored (presumed unmodified).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, cache_path) ⇒ CachedCookbook

Returns a new instance of CachedCookbook.



54
55
56
57
58
59
60
61
# File 'lib/chef-dk/policyfile_lock.rb', line 54

def initialize(name, cache_path)
  @name = name
  @cache_path = cache_path
  @origin = nil
  @cache_key = nil
  @identifier = nil
  @dotted_decimal_identifier = nil
end

Instance Attribute Details

#cache_keyObject

The directory name in the cookbook cache where the cookbook is stored. By convention, this should be the name of the cookbook followed by a hyphen and then some sort of version identifier (depending on the cookbook source).



36
37
38
# File 'lib/chef-dk/policyfile_lock.rb', line 36

def cache_key
  @cache_key
end

#cache_pathObject (readonly)

The root of the cookbook cache.



52
53
54
# File 'lib/chef-dk/policyfile_lock.rb', line 52

def cache_path
  @cache_path
end

#dotted_decimal_identifierObject



71
72
73
# File 'lib/chef-dk/policyfile_lock.rb', line 71

def dotted_decimal_identifier
  @dotted_decimal_identifier || identifiers.dotted_decimal_identifier
end

#identifierObject



67
68
69
# File 'lib/chef-dk/policyfile_lock.rb', line 67

def identifier
  @identifier || identifiers.content_identifier
end

#nameObject (readonly)

The cookbook name (without any version or other info suffixed)



30
31
32
# File 'lib/chef-dk/policyfile_lock.rb', line 30

def name
  @name
end

#originObject

A URI pointing to the canonical source of the cookbook.



39
40
41
# File 'lib/chef-dk/policyfile_lock.rb', line 39

def origin
  @origin
end

Instance Method Details

#cookbook_pathObject



63
64
65
# File 'lib/chef-dk/policyfile_lock.rb', line 63

def cookbook_path
  File.join(cache_path, cache_key)
end

#identifiersObject



86
87
88
# File 'lib/chef-dk/policyfile_lock.rb', line 86

def identifiers
  @identifiers ||= CookbookProfiler::Identifiers.new(cookbook_path)
end

#to_lockObject



75
76
77
78
79
80
81
82
83
84
# File 'lib/chef-dk/policyfile_lock.rb', line 75

def to_lock
  validate!
  {
    "version" => identifiers.semver_version,
    "identifier" => identifier,
    "dotted_decimal_identifier" => dotted_decimal_identifier,
    "cache_key" => cache_key,
    "origin" => origin
  }
end

#validate!Object



90
91
92
93
94
# File 'lib/chef-dk/policyfile_lock.rb', line 90

def validate!
  unless File.exist?(cookbook_path)
    raise CachedCookbookNotFound, "Cookbook `#{name}' not found at expected cache location `#{cookbook_path}'"
  end
end