Class: PuppetFixtures::Symlink
- Inherits:
-
Object
- Object
- PuppetFixtures::Symlink
- Defined in:
- lib/puppet_fixtures.rb
Instance Method Summary collapse
-
#create ⇒ Object
Create a junction on Windows or otherwise a symlink works on windows and linux.
-
#initialize(target:, link:) ⇒ Symlink
constructor
A new instance of Symlink.
- #remove ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(target:, link:) ⇒ Symlink
Returns a new instance of Symlink.
412 413 414 415 |
# File 'lib/puppet_fixtures.rb', line 412 def initialize(target:, link:) @target = target @link = link end |
Instance Method Details
#create ⇒ Object
Create a junction on Windows or otherwise a symlink works on windows and linux
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/puppet_fixtures.rb', line 419 def create return if File.symlink?(@link) if PuppetFixtures.windows? begin require 'win32/dir' rescue LoadError # the require only works on windows end target = Pathname.new(@target).absolute? ? @target : File.join(File.dirname(@link), @target) if Dir.respond_to?(:create_junction) Dir.create_junction(@link, target) else warn 'win32-dir gem not installed, falling back to executing mklink directly' # TODO: use run_command system("call mklink /J \"#{@link.tr('/', '\\')}\" \"#{target.tr('/', '\\')}\"") end else FileUtils.ln_sf(@target, @link) end end |
#remove ⇒ Object
441 442 443 |
# File 'lib/puppet_fixtures.rb', line 441 def remove FileUtils.rm_f(@link) end |
#to_s ⇒ Object
445 446 447 448 |
# File 'lib/puppet_fixtures.rb', line 445 def to_s # TODO: relative? "#{@link} => #{@target}" end |