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:



11
12
13
14
15
16
# File 'lib/berkshelf/validator.rb', line 11

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:



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

def validate_files(cookbooks)
  Array(cookbooks).each do |cookbook|
    path = cookbook.path.to_s

    files = Dir.chdir(path) do
      Dir.glob(File.join("**", "*.rb")).select do |f|
        f = File.join(path, f)
        parent = Pathname.new(path).dirname.to_s
        f.gsub(parent, "") =~ /[[:space:]]/
      end
    end

    raise InvalidCookbookFiles.new(cookbook, files) unless files.empty?
  end
end