Sha256: a115e50a57f6008b988a61e9d8a0b8cb9dbe289763e6bdbde716edca17a18ef1
Contents?: true
Size: 1.25 KB
Versions: 8
Compression:
Stored size: 1.25 KB
Contents
require 'json' require 'yaml' require 'librarian/manifest' module Librarian module Chef module ManifestReader extend self MANIFESTS = %w(metadata.json metadata.yml metadata.yaml metadata.rb) def manifest_path(path) MANIFESTS.map{|s| path.join(s)}.find{|s| s.exist?} end def read_manifest(name, manifest_path) case manifest_path.extname when ".json" then JSON.parse(manifest_path.read) when ".yml", ".yaml" then YAML.load(manifest_path.read) when ".rb" then compile_manifest(name, manifest_path.dirname) end end def compile_manifest(name, path) # Inefficient, if there are many cookbooks with uncompiled metadata. require 'chef/json_compat' require 'chef/cookbook/metadata' md = ::Chef::Cookbook::Metadata.new md.name(name) md.from_file(path.join('metadata.rb').to_s) {"name" => md.name, "version" => md.version, "dependencies" => md.dependencies} end def manifest?(name, path) path = Pathname.new(path) !!manifest_path(path) end def check_manifest(name, manifest_path) manifest = read_manifest(name, manifest_path) manifest["name"] == name end end end end
Version data entries
8 entries across 8 versions & 2 rubygems