Class: Promote::Cookbook
- Inherits:
-
Object
- Object
- Promote::Cookbook
- Defined in:
- lib/promote/cookbook.rb
Instance Method Summary collapse
- #dependencies ⇒ Object
- #dependencies_changed_after_update? ⇒ Boolean
- #dependency_hash(environment_cookbook_name) ⇒ Object
-
#initialize(cookbook_name, config) ⇒ Cookbook
constructor
A new instance of Cookbook.
- #metadata ⇒ Object
- #metadata_dependencies ⇒ Object
- #path ⇒ Object
- #raw_metadata ⇒ Object
- #stamp_commit(commit) ⇒ Object
- #sync_berksfile(update = false) ⇒ Object
- #sync_latest_app_cookbooks(environment_cookbook_name) ⇒ Object
- #version(version = nil) ⇒ Object
- #version=(version) ⇒ Object
Constructor Details
#initialize(cookbook_name, config) ⇒ Cookbook
Returns a new instance of Cookbook.
7 8 9 10 11 12 |
# File 'lib/promote/cookbook.rb', line 7 def initialize(cookbook_name, config) @name = cookbook_name @config = config @metadata_path = File.join(path, 'metadata.rb') @berks_path = File.join(path, "Berksfile") end |
Instance Method Details
#dependencies ⇒ Object
14 15 16 |
# File 'lib/promote/cookbook.rb', line 14 def dependencies @dependencies ||= get_synced_dependencies_from_lockfile end |
#dependencies_changed_after_update? ⇒ Boolean
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/promote/cookbook.rb', line 65 def dependencies_changed_after_update? old_deps = dependencies sync_berksfile(true) new_deps = get_dependencies_from_lockfile return true unless old_deps.count == new_deps.count old_deps.each do |k,v| if k != @name return true unless new_deps[k] == v end end return false end |
#dependency_hash(environment_cookbook_name) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/promote/cookbook.rb', line 81 def dependency_hash(environment_cookbook_name) sync_latest_app_cookbooks(environment_cookbook_name) hash_src = '' dependencies.each do | k,v | hash_src << "#{k}::#{v}::" end Digest::SHA1.hexdigest(hash_src) end |
#metadata ⇒ Object
50 51 52 |
# File 'lib/promote/cookbook.rb', line 50 def @metadata ||= end |
#metadata_dependencies ⇒ Object
18 19 20 |
# File 'lib/promote/cookbook.rb', line 18 def .dependencies end |
#path ⇒ Object
54 55 56 |
# File 'lib/promote/cookbook.rb', line 54 def path File.join(@config.cookbook_directory, @name) end |
#raw_metadata ⇒ Object
46 47 48 |
# File 'lib/promote/cookbook.rb', line 46 def @raw_metadata ||= File.read(@metadata_path) end |
#stamp_commit(commit) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/promote/cookbook.rb', line 37 def stamp_commit(commit) commit_line = "#sha1 '#{commit}'" new_content = .gsub(/#sha1.*$/, commit_line) if new_content[/#sha1.*$/].nil? new_content += "\n#{commit_line}" end (new_content) end |
#sync_berksfile(update = false) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/promote/cookbook.rb', line 58 def sync_berksfile(update=false) return if berksfile.nil? update = false unless File.exist?("#{@berks_path}.lock") update ? berksfile_update : berksfile.install end |
#sync_latest_app_cookbooks(environment_cookbook_name) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/promote/cookbook.rb', line 90 def sync_latest_app_cookbooks(environment_cookbook_name) result = {} latest_server_cookbooks = Utils.chef_server_cookbooks(@config, 1) env_cookbook = Cookbook.new(environment_cookbook_name, @config) env_cookbook..each do |key| cb_key = key[0] next if cb_key == @name || !latest_server_cookbooks.has_key?(cb_key) latest_version = latest_server_cookbooks[cb_key]['versions'][0]['version'] if dependencies.keys.include?(cb_key) && latest_version > dependencies[cb_key].to_s berksfile_update(cb_key) result[cb_key] = latest_version end end result end |
#version(version = nil) ⇒ Object
22 23 24 |
# File 'lib/promote/cookbook.rb', line 22 def version(version=nil) .version end |
#version=(version) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/promote/cookbook.rb', line 26 def version=(version) version_line = [/^\s*version\s.*$/] current_version = version_line[/('|").*("|')/].gsub(/('|")/,"") if current_version != version.to_s new_version_line = version_line.gsub(current_version, version.to_s) new_content = .gsub(version_line, new_version_line) (new_content) end version end |