lib/berkshelf/cached_cookbook.rb in berkshelf-7.0.8 vs lib/berkshelf/cached_cookbook.rb in berkshelf-7.0.9
- old
+ new
@@ -1,8 +1,8 @@
require "chef/cookbook/cookbook_version_loader"
require "chef/cookbook/syntax_check"
-require "berkshelf/errors"
+require_relative "errors"
require "chef/json_compat"
module Berkshelf
class CachedCookbook
class << self
@@ -64,11 +64,11 @@
def loader
@loader ||=
begin
loader = Chef::Cookbook::CookbookVersionLoader.new(@path)
- loader.load_cookbooks
+ loader.load!
loader
end
end
def cookbook_version
@@ -149,11 +149,12 @@
end
def validate
raise IOError, "No Cookbook found at: #{path}" unless path.exist?
- syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cookbook_name, path)
+ syntax_checker = Chef::Cookbook::SyntaxCheck.new(path.to_path)
+
unless syntax_checker.validate_ruby_files
raise Berkshelf::Errors::CookbookSyntaxError, "Invalid ruby files in cookbook: #{cookbook_name} (#{version})."
end
unless syntax_checker.validate_templates
raise Berkshelf::Errors::CookbookSyntaxError, "Invalid template files in cookbook: #{cookbook_name} (#{version})."
@@ -164,9 +165,10 @@
def compile_metadata(path = self.path)
json_file = "#{path}/metadata.json"
rb_file = "#{path}/metadata.rb"
return nil if File.exist?(json_file)
+
md = Chef::Cookbook::Metadata.new
md.from_file(rb_file)
f = File.open(json_file, "w")
f.write(Chef::JSONCompat.to_json_pretty(md))
f.close