Sha256: 1716a209ea3d20bf7c9c40cd34739041fb5b2a9863e0698f8e5ae378925e72b0

Contents?: true

Size: 1.2 KB

Versions: 13

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'pathspec'

module PuppetlabsSpecHelper
  module Tasks
    # Helpers for validating symlinks.
    class CheckSymlinks
      DEFAULT_IGNORED = [
        '/.git/',
        '/.bundle/',
        '/vendor/'
      ].freeze

      IGNORE_LIST_FILES = [
        '.pdkignore',
        '.gitignore'
      ].freeze

      def check(dir = Dir.pwd)
        dir = Pathname.new(dir) unless dir.is_a?(Pathname)
        results = []

        dir.each_child(true) do |child|
          next if ignored?(child.to_s)

          if child.symlink?
            results << child
          elsif child.directory? && child.basename.to_s !~ /^(\.git|\.?bundle)$/
            results.concat(check(child))
          end
        end

        results
      end

      def ignored?(path)
        path = "#{path}/" if File.directory?(path)

        !ignore_pathspec.match_paths([path], Dir.pwd).empty?
      end

      def ignore_pathspec
        @ignore_pathspec ||= PathSpec.new(DEFAULT_IGNORED).tap do |pathspec|
          IGNORE_LIST_FILES.each do |f|
            next unless File.file?(f) && File.readable?(f)

            File.open(f, 'r') { |fd| pathspec.add(fd) }
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
puppetlabs_spec_helper-7.3.1 lib/puppetlabs_spec_helper/tasks/check_symlinks.rb
puppetlabs_spec_helper-7.2.0 lib/puppetlabs_spec_helper/tasks/check_symlinks.rb
puppetlabs_spec_helper-7.1.0 lib/puppetlabs_spec_helper/tasks/check_symlinks.rb
puppetlabs_spec_helper-7.0.5 lib/puppetlabs_spec_helper/tasks/check_symlinks.rb
puppetlabs_spec_helper-7.0.4 lib/puppetlabs_spec_helper/tasks/check_symlinks.rb
puppetlabs_spec_helper-7.0.3 lib/puppetlabs_spec_helper/tasks/check_symlinks.rb
puppetlabs_spec_helper-7.0.2 lib/puppetlabs_spec_helper/tasks/check_symlinks.rb
puppetlabs_spec_helper-7.0.1 lib/puppetlabs_spec_helper/tasks/check_symlinks.rb
puppetlabs_spec_helper-6.0.3 lib/puppetlabs_spec_helper/tasks/check_symlinks.rb
puppetlabs_spec_helper-6.0.2 lib/puppetlabs_spec_helper/tasks/check_symlinks.rb
puppetlabs_spec_helper-6.0.1 lib/puppetlabs_spec_helper/tasks/check_symlinks.rb
puppetlabs_spec_helper-6.0.0 lib/puppetlabs_spec_helper/tasks/check_symlinks.rb
puppetlabs_spec_helper-6.0.0.rc.1 lib/puppetlabs_spec_helper/tasks/check_symlinks.rb