Class: Bundler::Thor::Actions::CreateLink

Inherits:
CreateFile show all
Defined in:
lib/bundler/vendor/thor/lib/thor/actions/create_link.rb

Overview

CreateLink is a subset of CreateFile, which instead of taking a block of data, just takes a source string from the user.

Instance Attribute Summary collapse

Attributes inherited from EmptyDirectory

#base, #config, #destination, #given_destination, #relative_destination

Instance Method Summary collapse

Methods inherited from CreateFile

#initialize, #render

Methods inherited from EmptyDirectory

#initialize, #revoke!

Constructor Details

This class inherits a constructor from Bundler::Thor::Actions::CreateFile

Instance Attribute Details

#dataObject (readonly)

:nodoc:



28
29
30
# File 'lib/bundler/vendor/thor/lib/thor/actions/create_link.rb', line 28

def data
  @data
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/bundler/vendor/thor/lib/thor/actions/create_link.rb', line 55

def exists?
  super || File.symlink?(destination)
end

#identical?Boolean

Checks if the content of the file at the destination is identical to the rendered result.

Returns

Boolean

true if it is identical, false otherwise.

Returns:

  • (Boolean)


35
36
37
# File 'lib/bundler/vendor/thor/lib/thor/actions/create_link.rb', line 35

def identical?
  exists? && File.identical?(render, destination)
end

#invoke!Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bundler/vendor/thor/lib/thor/actions/create_link.rb', line 39

def invoke!
  invoke_with_conflict_check do
    require "fileutils"
    FileUtils.mkdir_p(File.dirname(destination))
    # Create a symlink by default
    config[:symbolic] = true if config[:symbolic].nil?
    File.unlink(destination) if exists?
    if config[:symbolic]
      File.symlink(render, destination)
    else
      File.link(render, destination)
    end
  end
  given_destination
end