Sha256: 120398177235a71144444089669155744b32955032f0a789adb51992aabb948b

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

module Minimart
  module Utils
    # FileHelper contains helper methods for dealing with the file system.
    module FileHelper

      # Find the first cookbook in the given path
      # @param [String] path The directory to search for cookbooks in
      # @return [String] The path to the cookbook
      def self.cookbook_path_in_directory(path)
        cookbook_in_path?(path) ? path : find_cookbooks_in_directory(path).first
      end

      # List all of the cookbooks in a given directory
      # @param [String] path The directory to find cookbooks in
      # @return [Array<String>] An array of paths to any cookbooks found in the supplied path.
      def self.find_cookbooks_in_directory(path)
        Dir.glob(File.join(path, '/*/')).select { |d| cookbook_in_path?(d) }
      end

      # Determine whether or not a given directory contains a cookbook.
      # @param [String] path The directory to check
      # @return [Boolean]
      def self.cookbook_in_path?(path)
        file_exists?(File.join(path, 'metadata.json')) ||
          file_exists?(File.join(path, 'metadata.rb'))
      end

      def self.file_exists?(path)
        File.exists?(path)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
minimart-1.0.2 lib/minimart/utils/file_helper.rb
minimart-1.0.1 lib/minimart/utils/file_helper.rb
minimart-0.0.1 lib/minimart/utils/file_helper.rb