Sha256: b61cbb56f09b01fdb0ca435bc2ad29fb814c936d27a77d7fa49bf827dc66e605

Contents?: true

Size: 1.15 KB

Versions: 25

Compression:

Stored size: 1.15 KB

Contents

module Berkshelf
  module Validator
    class << self
      # Perform a complete cookbook validation checking:
      #   * File names for inappropriate characters
      #   * Invalid Ruby syntax
      #   * Invalid ERB templates
      #
      # @param [Array<CachedCookbook>, CachedCookbook] cookbooks
      #   the Cookbook(s) to validate
      def validate(cookbooks)
        Array(cookbooks).each do |cookbook|
          validate_files(cookbook)
          cookbook.validate
        end
      end

      # Validate that the given cookbook does not have "bad" files. Currently
      # this means including spaces in filenames (such as recipes)
      #
      # @param [Array<CachedCookbook>, CachedCookbook] cookbooks
      #  the Cookbook(s) to validate
      def validate_files(cookbooks)
        Array(cookbooks).each do |cookbook|
          path = cookbook.path.to_s

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

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

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
berkshelf-5.5.0 lib/berkshelf/validator.rb
berkshelf-5.4.0 lib/berkshelf/validator.rb
berkshelf-5.3.0 lib/berkshelf/validator.rb
berkshelf-5.2.0 lib/berkshelf/validator.rb
berkshelf-5.1.0 lib/berkshelf/validator.rb
berkshelf-5.0.0 lib/berkshelf/validator.rb
berkshelf-4.3.5 lib/berkshelf/validator.rb
berkshelf-4.3.3 lib/berkshelf/validator.rb
berkshelf-4.3.2 lib/berkshelf/validator.rb
berkshelf-4.3.1 lib/berkshelf/validator.rb
berkshelf-4.3.0 lib/berkshelf/validator.rb
berkshelf-4.2.3 lib/berkshelf/validator.rb
berkshelf-4.2.2 lib/berkshelf/validator.rb
berkshelf-4.2.1 lib/berkshelf/validator.rb
berkshelf-4.2.0 lib/berkshelf/validator.rb
berkshelf-4.1.1 lib/berkshelf/validator.rb
berkshelf-4.1.0 lib/berkshelf/validator.rb
berkshelf-4.0.1 lib/berkshelf/validator.rb
berkshelf-4.0.0 lib/berkshelf/validator.rb
berkshelf-3.3.0 lib/berkshelf/validator.rb