Sha256: b07d1b063e0d1163e2553a4f33619f0c06ebbc617cbe7ae9f7979887cf614b0c

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

require 'buff/ignore'

module Ridley::Chef
  class Chefignore < Buff::Ignore::IgnoreFile
    include Ridley::Logging

    # The filename of the chefignore
    #
    # @return [String]
    FILENAME = 'chefignore'.freeze

    # Create a new chefignore
    #
    # @param [#to_s] path
    #   the path to find a chefignore from (default: `Dir.pwd`)
    def initialize(path = Dir.pwd)
      ignore = chefignore(path)

      if ignore
        log.debug "Using '#{FILENAME}' at '#{ignore}'"
      else
        log.debug "Could not find '#{FILENAME}' at '#{path}'"
      end

      super(ignore, base: path)
    end

    private

      # Find the chefignore file in the current directory
      #
      # @return [String, nil]
      #   the path to the chefignore file or nil if one was not
      #   found
      def chefignore(path)
        Pathname.new(path).ascend do |dir|
          next unless dir.directory?

          [
            dir.join(FILENAME),
            dir.join('cookbooks', FILENAME),
            dir.join('.chef',     FILENAME),
          ].each do |possible|
            return possible.expand_path.to_s if possible.exist?
          end
        end

        nil
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ridley-2.5.1 lib/ridley/chef/chefignore.rb
ridley-2.5.0 lib/ridley/chef/chefignore.rb
ridley-2.4.4 lib/ridley/chef/chefignore.rb
ridley-2.4.3 lib/ridley/chef/chefignore.rb
ridley-2.4.2 lib/ridley/chef/chefignore.rb
ridley-2.4.1 lib/ridley/chef/chefignore.rb