Class: PuppetlabsSpecHelper::Tasks::CheckSymlinks

Inherits:
Object
  • Object
show all
Defined in:
lib/puppetlabs_spec_helper/tasks/check_symlinks.rb

Constant Summary collapse

DEFAULT_IGNORED =
[
  '/.git/',
  '/.bundle/',
  '/vendor/',
].freeze
IGNORE_LIST_FILES =
[
  '.pdkignore',
  '.gitignore',
].freeze

Instance Method Summary collapse

Instance Method Details

#check(dir = Dir.pwd) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/puppetlabs_spec_helper/tasks/check_symlinks.rb', line 20

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 !~ %r{^(\.git|\.?bundle)$}
      results.concat(check(child))
    end
  end

  results
end

#ignore_pathspecObject


43
44
45
46
47
48
49
50
51
# File 'lib/puppetlabs_spec_helper/tasks/check_symlinks.rb', line 43

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

#ignored?(path) ⇒ Boolean

Returns:

  • (Boolean)

37
38
39
40
41
# File 'lib/puppetlabs_spec_helper/tasks/check_symlinks.rb', line 37

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

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