lib/berkshelf/validator.rb in berkshelf-8.0.5 vs lib/berkshelf/validator.rb in berkshelf-8.0.7
- old
+ new
@@ -1,5 +1,7 @@
+require 'chef/version_class'
+
module Berkshelf
module Validator
class << self
# Perform a complete cookbook validation checking:
# * File names for inappropriate characters
@@ -23,11 +25,20 @@
def validate_files(cookbooks)
Array(cookbooks).each do |cookbook|
base, name = Pathname.new(cookbook.path.to_s).split
files = Dir.glob("#{name}/**/*.rb", base: base.to_s).select { |f| f =~ /[[:space:]]/ }
+ validate_versions(cookbook)
raise InvalidCookbookFiles.new(cookbook, files) unless files.empty?
+ end
+ end
+
+ def validate_versions(cookbook)
+ cookbook_dependencies = cookbook.dependencies
+ cookbook_dependencies.each do |cookbook_name, cookbook_version|
+ version = cookbook_version.gsub(/[^\d,\.]/, '')
+ Chef::Version.new(version)
end
end
end
end
end