Module: Librarian::Chef::ManifestReader

Extended by:
ManifestReader
Included in:
ManifestReader
Defined in:
lib/librarian/chef/manifest_reader.rb

Constant Summary collapse

MANIFESTS =
%w(metadata.json metadata.yml metadata.yaml metadata.rb)

Instance Method Summary collapse

Instance Method Details

#check_manifest(name, manifest_path) ⇒ Object



37
38
39
40
# File 'lib/librarian/chef/manifest_reader.rb', line 37

def check_manifest(name, manifest_path)
  manifest = read_manifest(name, manifest_path)
  manifest["name"] == name
end

#compile_manifest(name, path) ⇒ Object



27
28
29
30
# File 'lib/librarian/chef/manifest_reader.rb', line 27

def compile_manifest(name, path)
  md = Metadata.new('metadata.rb', path)
  { "name" => name, "version" => md.version, "dependencies" => md.dependencies }
end

#manifest?(name, path) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/librarian/chef/manifest_reader.rb', line 32

def manifest?(name, path)
  path = Pathname.new(path)
  !!manifest_path(path)
end

#manifest_path(path) ⇒ Object



15
16
17
# File 'lib/librarian/chef/manifest_reader.rb', line 15

def manifest_path(path)
  MANIFESTS.map{|s| path.join(s)}.find{|s| s.exist?}
end

#read_manifest(name, manifest_path) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/librarian/chef/manifest_reader.rb', line 19

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