Class: FileUtils::Entry_

Inherits:
Object show all
Defined in:
lib/standard/facets/fileutils/ln_r.rb

Overview

:nodoc:

Constant Summary collapse

DIRECTORY_TERM =
"(?=/|\\z)".freeze
SYSCASE =
File::FNM_SYSCASE.nonzero? ? "-i" : ""

Instance Method Summary collapse

Instance Method Details

#descendant_diretory?(descendant, ascendant) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/standard/facets/fileutils/ln_r.rb', line 90

def descendant_diretory?(descendant, ascendant)
  /\A(?#{SYSCASE}:#{Regexp.quote(ascendant)})#{DIRECTORY_TERM}/ =~ File.dirname(descendant)
end


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/standard/facets/fileutils/ln_r.rb', line 64

def link(dest)
  case
  when directory?
    if !File.exist?(dest) and descendant_diretory?(dest, path)
      raise ArgumentError, "cannot link directory %s to itself %s" % [path, dest]
    end
    begin
      Dir.mkdir dest
    rescue
      raise unless File.directory?(dest)
    end
  else file?
    File.link path(), dest
  end
end