class Bosh::Workspace::DeploymentPatch
Attributes
releases[R]
stemcells[R]
templates_ref[R]
Public Class Methods
create(deployment_file, templates_dir)
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 6 def self.create(deployment_file, templates_dir) if File.exist? File.join(templates_dir, '.git') ref = Rugged::Repository.new(templates_dir).head.target.oid end deployment = YAML.load_file deployment_file new(deployment["stemcells"], deployment["releases"], ref) end
from_file(patch_file)
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 14 def self.from_file(patch_file) a = YAML.load_file patch_file new(a["stemcells"], a["releases"], a["templates_ref"]) end
new(stemcells, releases, templates_ref)
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 19 def initialize(stemcells, releases, templates_ref) @stemcells = stemcells @releases = releases @templates_ref = templates_ref end
Public Instance Methods
apply(deployment_file, templates_dir)
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 44 def apply(deployment_file, templates_dir) checkout_submodule(templates_dir, templates_ref) if templates_ref deployment = YAML.load_file deployment_file deployment.merge! 'stemcells' => stemcells, 'releases' => releases IO.write(deployment_file, deployment.to_yaml) end
changes(patch)
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 51 def changes(patch) { stemcells: item_changes(stemcells, patch.stemcells), releases: item_changes(releases, patch.releases), templates_ref: item_changes(templates_ref, patch.templates_ref) }.reject { |_, v| v.empty? } end
changes?(patch)
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 59 def changes?(patch) !changes(patch).empty? end
perform_validation(options = {})
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 25 def perform_validation(options = {}) Schemas::DeploymentPatch.new.validate to_hash rescue Membrane::SchemaValidationError => e errors << e.message end
to_file(patch_file)
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 40 def to_file(patch_file) IO.write(patch_file, to_yaml) end
to_hash()
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 31 def to_hash { "stemcells" => stemcells, "releases" => releases } .tap { |h| h["templates_ref"] = templates_ref if templates_ref } end
to_yaml()
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 36 def to_yaml to_hash.to_yaml end
Private Instance Methods
checkout_submodule(dir, ref)
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 85 def checkout_submodule(dir, ref) repo = Rugged::Repository.new(dir) repo.checkout ref, strategy: :force end
item_changes(old, new)
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 65 def item_changes(old, new) return [] unless old old, new = presentify_item(old), presentify_item(new) changes = HashDiff.diff(old, new).map { |a| a.join(' ').squeeze(' ') } presentify_changes(changes).join(', ') end
presentify_changes(changes)
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 72 def presentify_changes(changes) translations = { '~' => "changed", '-' => 'removed', '+' => 'added' } changes.map { |l| l.gsub(/^./) { |m| translations.fetch(m, m) } } end
presentify_item(item)
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 77 def presentify_item(item) item.is_a?(Array) ? versions_hash(item) : item[0..6] end
versions_hash(array)
click to toggle source
# File lib/bosh/workspace/deployment_patch.rb, line 81 def versions_hash(array) Hash[array.map { |v| [v["name"], v["version"]]}] end