Module: Berkshelf::Validator

Defined in:
lib/berkshelf/validator.rb

Class Method Summary collapse

Class Method Details

.validate(cookbooks) ⇒ Object

Perform a complete cookbook validation checking:

* File names for inappropriate characters
* Invalid Ruby syntax
* Invalid ERB templates

Parameters:



13
14
15
16
17
18
# File 'lib/berkshelf/validator.rb', line 13

def validate(cookbooks)
  Array(cookbooks).each do |cookbook|
    validate_files(cookbook)
    cookbook.validate
  end
end

.validate_files(cookbooks) ⇒ Object

Validate that the given cookbook does not have “bad” files. Currently this means including spaces in filenames (such as recipes)

Parameters:



25
26
27
28
29
30
31
32
33
34
# File 'lib/berkshelf/validator.rb', line 25

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

.validate_versions(cookbook) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/berkshelf/validator.rb', line 36

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