Sha256: ba51e36367eeabd954ddc7f5aa8379492fddcbc9ad14e2457bf4bb2e83709714

Contents?: true

Size: 1.45 KB

Versions: 21

Compression:

Stored size: 1.45 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(binread(manifest_path))
        when ".yml", ".yaml" then YAML.load(binread(manifest_path))
        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

    private

      if IO.respond_to?(:binread)
        def binread(path)
          path.binread
        end
      else
        def binread(path)
          path.read
        end
      end

    end
  end
end

Version data entries

21 entries across 21 versions & 5 rubygems

Version Path
librarian-puppet-0.9.10 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-0.9.9 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-chef-0.0.1.beta.2 lib/librarian/chef/manifest_reader.rb
librarian-chef-0.0.1.beta.1 lib/librarian/chef/manifest_reader.rb
librarian-puppet-lmco-0.9.8.2 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-0.9.8 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-maestrodev-0.9.7.5 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-maestrodev-0.9.7.4 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-maestrodev-0.9.7.3 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-0.0.26 lib/librarian/chef/manifest_reader.rb
librarian-puppet-maestrodev-0.9.7.2 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-maestrodev-0.9.7.1 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-maestrodev-0.9.7 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-0.0.25 lib/librarian/chef/manifest_reader.rb
librarian-puppet-0.9.7 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-0.9.6 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-0.9.5 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-0.9.4 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-0.9.3 vendor/librarian/lib/librarian/chef/manifest_reader.rb
librarian-puppet-0.9.2 vendor/librarian/lib/librarian/chef/manifest_reader.rb