Class: ChefDK::PolicyfileLock::CachedCookbook
- Inherits:
-
Object
- Object
- ChefDK::PolicyfileLock::CachedCookbook
- 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
-
#cache_key ⇒ Object
The directory name in the cookbook cache where the cookbook is stored.
-
#cache_path ⇒ Object
readonly
The root of the cookbook cache.
- #dotted_decimal_identifier ⇒ Object
- #identifier ⇒ Object
-
#name ⇒ Object
readonly
The cookbook name (without any version or other info suffixed).
-
#origin ⇒ Object
A URI pointing to the canonical source of the cookbook.
Instance Method Summary collapse
- #cookbook_path ⇒ Object
- #identifiers ⇒ Object
-
#initialize(name, cache_path) ⇒ CachedCookbook
constructor
A new instance of CachedCookbook.
- #to_lock ⇒ Object
- #validate! ⇒ Object
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_key ⇒ Object
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_path ⇒ Object (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_identifier ⇒ Object
71 72 73 |
# File 'lib/chef-dk/policyfile_lock.rb', line 71 def dotted_decimal_identifier @dotted_decimal_identifier || identifiers.dotted_decimal_identifier end |
#identifier ⇒ Object
67 68 69 |
# File 'lib/chef-dk/policyfile_lock.rb', line 67 def identifier @identifier || identifiers.content_identifier end |
#name ⇒ Object (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 |
#origin ⇒ Object
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_path ⇒ Object
63 64 65 |
# File 'lib/chef-dk/policyfile_lock.rb', line 63 def cookbook_path File.join(cache_path, cache_key) end |
#identifiers ⇒ Object
86 87 88 |
# File 'lib/chef-dk/policyfile_lock.rb', line 86 def identifiers @identifiers ||= CookbookProfiler::Identifiers.new(cookbook_path) end |
#to_lock ⇒ Object
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 |