Sha256: db116af3cb7fffe5ca9473f0cf8cb5a68a95c599274546fd7c65c4bf3655f8aa

Contents?: true

Size: 1.16 KB

Versions: 13

Compression:

Stored size: 1.16 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 Chefignore at '#{ignore}'"
      else
        log.debug "Could not find a Chefignore 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

13 entries across 13 versions & 1 rubygems

Version Path
ridley-2.4.0 lib/ridley/chef/chefignore.rb
ridley-2.3.0 lib/ridley/chef/chefignore.rb
ridley-2.2.0 lib/ridley/chef/chefignore.rb
ridley-2.1.0 lib/ridley/chef/chefignore.rb
ridley-2.0.0 lib/ridley/chef/chefignore.rb
ridley-1.7.1 lib/ridley/chef/chefignore.rb
ridley-1.7.0 lib/ridley/chef/chefignore.rb
ridley-1.6.0 lib/ridley/chef/chefignore.rb
ridley-1.5.3 lib/ridley/chef/chefignore.rb
ridley-1.5.2 lib/ridley/chef/chefignore.rb
ridley-1.5.1 lib/ridley/chef/chefignore.rb
ridley-1.5.0 lib/ridley/chef/chefignore.rb
ridley-1.4.1 lib/ridley/chef/chefignore.rb