Sha256: 414cd9675ea9f7aabca4a6db5756b305baceb4e355a26a0d5f2fa535a5ac40f6

Contents?: true

Size: 1.08 KB

Versions: 20

Compression:

Stored size: 1.08 KB

Contents

require 'json'
require 'yaml'

require 'librarian/manifest'

module Librarian
  module Chef
    class Manifest < Manifest

      module Helpers

        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)
          JSON.parse(::Chef::JSONCompat.to_json_pretty(md))
        end

      end

      include Helpers
      extend Helpers

    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
librarian-0.0.20 lib/librarian/chef/manifest.rb
librarian-0.0.19 lib/librarian/chef/manifest.rb
librarian-0.0.18 lib/librarian/chef/manifest.rb
librarian-0.0.17 lib/librarian/chef/manifest.rb
librarian-0.0.16 lib/librarian/chef/manifest.rb
librarian-0.0.15 lib/librarian/chef/manifest.rb
librarian-0.0.14 lib/librarian/chef/manifest.rb
librarian-0.0.13 lib/librarian/chef/manifest.rb
librarian-0.0.12 lib/librarian/chef/manifest.rb
librarian-0.0.11 lib/librarian/chef/manifest.rb
librarian-0.0.10 lib/librarian/chef/manifest.rb
librarian-0.0.9 lib/librarian/chef/manifest.rb
librarian-0.0.8 lib/librarian/chef/manifest.rb
librarian-0.0.7 lib/librarian/chef/manifest.rb
librarian-0.0.6 lib/librarian/chef/manifest.rb
librarian-0.0.5 lib/librarian/chef/manifest.rb
librarian-0.0.4 lib/librarian/chef/manifest.rb
librarian-0.0.3 lib/librarian/chef/manifest.rb
librarian-0.0.2 lib/librarian/chef/manifest.rb
librarian-0.0.1 lib/librarian/chef/manifest.rb