Sha256: 98215ee460c2a79a3223e5f856775c84719493d1e824ae8a6ed4c8fd659866b4

Contents?: true

Size: 1.1 KB

Versions: 22

Compression:

Stored size: 1.1 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}'"
      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

22 entries across 22 versions & 1 rubygems

Version Path
ridley-5.1.1 lib/ridley/chef/chefignore.rb
ridley-5.1.0 lib/ridley/chef/chefignore.rb
ridley-5.0.0 lib/ridley/chef/chefignore.rb
ridley-4.6.1 lib/ridley/chef/chefignore.rb
ridley-4.6.0 lib/ridley/chef/chefignore.rb
ridley-4.5.1 lib/ridley/chef/chefignore.rb
ridley-4.5.0 lib/ridley/chef/chefignore.rb
ridley-4.4.3 lib/ridley/chef/chefignore.rb
ridley-4.4.2 lib/ridley/chef/chefignore.rb
ridley-4.4.1 lib/ridley/chef/chefignore.rb
ridley-4.4.0 lib/ridley/chef/chefignore.rb
ridley-4.3.2 lib/ridley/chef/chefignore.rb
ridley-4.3.1 lib/ridley/chef/chefignore.rb
ridley-4.3.0 lib/ridley/chef/chefignore.rb
ridley-4.2.0 lib/ridley/chef/chefignore.rb
ridley-4.1.2 lib/ridley/chef/chefignore.rb
ridley-4.1.1 lib/ridley/chef/chefignore.rb
ridley-4.1.0 lib/ridley/chef/chefignore.rb
ridley-4.0.0 lib/ridley/chef/chefignore.rb
ridley-3.1.0 lib/ridley/chef/chefignore.rb