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

Version Path
librarian-0.0.24 lib/librarian/chef/manifest_reader.rb
librarian-puppet-0.9.1 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-0.9.0 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-0.0.1.pre2 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-0.0.1.pre vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-0.0.23 lib/librarian/chef/manifest_reader.rb
librarian-0.0.22 lib/librarian/chef/manifest_reader.rb
librarian-0.0.21 lib/librarian/chef/manifest_reader.rb