Sha256: 26def45c82f1ae4c52c9b04f9763618103f0d8a63d495643fde4f8c605bb1848

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 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|
          base, name = Pathname.new(cookbook.path.to_s).split

          files = Dir.glob("#{name}/**/*.rb", base: base.to_s).select { |f| f =~ /[[:space:]]/ }

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
berkshelf-8.0.5 lib/berkshelf/validator.rb
berkshelf-8.0.2 lib/berkshelf/validator.rb
berkshelf-8.0.1 lib/berkshelf/validator.rb
berkshelf-8.0.0 lib/berkshelf/validator.rb
berkshelf-7.2.2 lib/berkshelf/validator.rb
berkshelf-7.2.1 lib/berkshelf/validator.rb
berkshelf-7.2.0 lib/berkshelf/validator.rb