module CFManifests::Builder

Public Instance Methods

build(file) click to toggle source

parse a manifest and merge with its inherited manifests

# File lib/manifests/loader/builder.rb, line 6
def build(file)
  manifest = YAML.load_file file
  raise CFManifests::InvalidManifest.new(file) unless manifest

  Array(manifest["inherit"]).each do |path|
    manifest = merge_parent(path, manifest)
  end

  manifest.delete("inherit")

  manifest
end

Private Instance Methods

merge_manifest(parent, child) click to toggle source

deep hash merge

# File lib/manifests/loader/builder.rb, line 27
def merge_manifest(parent, child)
  merge = proc do |_, old, new|
    if new.is_a?(Hash) && old.is_a?(Hash)
      old.merge(new, &merge)
    else
      new
    end
  end

  parent.merge(child, &merge)
end
merge_parent(parent_path, child) click to toggle source

merge the manifest at `parent_path' into the `child'

# File lib/manifests/loader/builder.rb, line 22
def merge_parent(parent_path, child)
  merge_manifest(build(from_manifest(parent_path)), child)
end