Class: ChefDK::CookbookProfiler::Identifiers
- Inherits:
-
Object
- Object
- ChefDK::CookbookProfiler::Identifiers
- Defined in:
- lib/chef-dk/cookbook_profiler/identifiers.rb
Instance Attribute Summary collapse
-
#cookbook_path ⇒ Object
readonly
Returns the value of attribute cookbook_path.
Instance Method Summary collapse
- #content_identifier ⇒ Object
- #cookbook_files ⇒ Object
- #cookbook_loader ⇒ Object
- #cookbook_version ⇒ Object
- #dotted_decimal_identifier ⇒ Object
- #files_with_checksums ⇒ Object
- #fingerprint_text ⇒ Object
-
#initialize(cookbook_path) ⇒ Identifiers
constructor
A new instance of Identifiers.
- #semver_version ⇒ Object
Constructor Details
#initialize(cookbook_path) ⇒ Identifiers
Returns a new instance of Identifiers.
28 29 30 |
# File 'lib/chef-dk/cookbook_profiler/identifiers.rb', line 28 def initialize(cookbook_path) @cookbook_path = cookbook_path end |
Instance Attribute Details
#cookbook_path ⇒ Object (readonly)
Returns the value of attribute cookbook_path.
26 27 28 |
# File 'lib/chef-dk/cookbook_profiler/identifiers.rb', line 26 def cookbook_path @cookbook_path end |
Instance Method Details
#content_identifier ⇒ Object
36 37 38 |
# File 'lib/chef-dk/cookbook_profiler/identifiers.rb', line 36 def content_identifier Digest::SHA1.new.hexdigest(fingerprint_text) end |
#cookbook_files ⇒ Object
61 62 63 |
# File 'lib/chef-dk/cookbook_profiler/identifiers.rb', line 61 def cookbook_files @files ||= cookbook_version.manifest_records_by_path end |
#cookbook_loader ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/chef-dk/cookbook_profiler/identifiers.rb', line 69 def cookbook_loader @cookbook_loader ||= begin loader = Chef::Cookbook::CookbookVersionLoader.new(cookbook_path) loader.load_cookbooks loader end end |
#cookbook_version ⇒ Object
65 66 67 |
# File 'lib/chef-dk/cookbook_profiler/identifiers.rb', line 65 def cookbook_version @cookbook_version ||= cookbook_loader.cookbook_version end |
#dotted_decimal_identifier ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/chef-dk/cookbook_profiler/identifiers.rb', line 40 def dotted_decimal_identifier hex_id = content_identifier major = hex_id[0...14] minor = hex_id[14...28] patch = hex_id[28..40] decimal_integers =[major, minor, patch].map {|hex| hex.to_i(16) } decimal_integers.join(".") end |
#files_with_checksums ⇒ Object
55 56 57 58 59 |
# File 'lib/chef-dk/cookbook_profiler/identifiers.rb', line 55 def files_with_checksums cookbook_files.inject([]) do |files_with_checksums, (_name, file_info)| files_with_checksums << [file_info["path"], file_info["checksum"]] end end |
#fingerprint_text ⇒ Object
49 50 51 52 53 |
# File 'lib/chef-dk/cookbook_profiler/identifiers.rb', line 49 def fingerprint_text files_with_checksums.sort {|a,b| a[0] <=> b[0]}.inject("") do |fingerprint, file_spec| fingerprint << "#{file_spec[0]}:#{file_spec[1]}\n" end end |
#semver_version ⇒ Object
32 33 34 |
# File 'lib/chef-dk/cookbook_profiler/identifiers.rb', line 32 def semver_version cookbook_version.version end |