forked from rubygems/bundler
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update vendored thor to 7416806146f252c589cfa0f7c154393bc498090a
- Loading branch information
Showing
28 changed files
with
913 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'thor/actions/create_file' | ||
|
||
class Thor | ||
module Actions | ||
|
||
# Create a new file relative to the destination root from the given source. | ||
# | ||
# ==== Parameters | ||
# destination<String>:: the relative path to the destination root. | ||
# source<String|NilClass>:: the relative path to the source root. | ||
# config<Hash>:: give :verbose => false to not log the status. | ||
# :: give :symbolic => false for hard link. | ||
# | ||
# ==== Examples | ||
# | ||
# create_link "config/apache.conf", "/etc/apache.conf" | ||
# | ||
def create_link(destination, *args, &block) | ||
config = args.last.is_a?(Hash) ? args.pop : {} | ||
source = args.first | ||
action CreateLink.new(self, destination, source, config) | ||
end | ||
alias :add_link :create_link | ||
|
||
# CreateLink is a subset of CreateFile, which instead of taking a block of | ||
# data, just takes a source string from the user. | ||
# | ||
class CreateLink < CreateFile #:nodoc: | ||
attr_reader :data | ||
|
||
# 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. | ||
# | ||
def identical? | ||
exists? && File.identical?(render, destination) | ||
end | ||
|
||
def invoke! | ||
invoke_with_conflict_check do | ||
FileUtils.mkdir_p(File.dirname(destination)) | ||
# Create a symlink by default | ||
config[:symbolic] ||= true | ||
File.unlink(destination) if exists? | ||
if config[:symbolic] | ||
File.symlink(render, destination) | ||
else | ||
File.link(render, destination) | ||
end | ||
end | ||
given_destination | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.