Sha256: 91ee3300209b7c39c2ce2822652e88413d3434a232c5e2e4d29153df355666fa

Contents?: true

Size: 1.23 KB

Versions: 17

Compression:

Stored size: 1.23 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.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
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
berkshelf-7.1.0 lib/berkshelf/validator.rb
berkshelf-7.0.10 lib/berkshelf/validator.rb
berkshelf-7.0.9 lib/berkshelf/validator.rb
berkshelf-7.0.8 lib/berkshelf/validator.rb
berkshelf-7.0.7 lib/berkshelf/validator.rb
berkshelf-6.3.4 lib/berkshelf/validator.rb
berkshelf-7.0.6 lib/berkshelf/validator.rb
berkshelf-7.0.5 lib/berkshelf/validator.rb
berkshelf-6.3.3 lib/berkshelf/validator.rb
berkshelf-7.0.4 lib/berkshelf/validator.rb
berkshelf-7.0.3 lib/berkshelf/validator.rb
berkshelf-7.0.2 lib/berkshelf/validator.rb
berkshelf-7.0.1 lib/berkshelf/validator.rb
berkshelf-7.0.0 lib/berkshelf/validator.rb
berkshelf-6.3.2 lib/berkshelf/validator.rb
berkshelf-6.3.1 lib/berkshelf/validator.rb
berkshelf-6.3.0 lib/berkshelf/validator.rb