aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/keg.rb
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew/keg.rb')
-rw-r--r--Library/Homebrew/keg.rb66
1 files changed, 35 insertions, 31 deletions
diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb
index ecbc4c6e0..d2c9e12e8 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -62,12 +62,17 @@ class Keg
end
# locale-specific directories have the form language[_territory][.codeset][@modifier]
- LOCALEDIR_RX = /(locale|man)\/([a-z]{2}|C|POSIX)(_[A-Z]{2})?(\.[a-zA-Z\-0-9]+(@.+)?)?/
+ LOCALEDIR_RX = %r{(locale|man)/([a-z]{2}|C|POSIX)(_[A-Z]{2})?(\.[a-zA-Z\-0-9]+(@.+)?)?}
INFOFILE_RX = %r{info/([^.].*?\.info|dir)$}
TOP_LEVEL_DIRECTORIES = %w[bin etc include lib sbin share var Frameworks].freeze
ALL_TOP_LEVEL_DIRECTORIES = (TOP_LEVEL_DIRECTORIES + %w[lib/pkgconfig share/locale share/man opt]).freeze
- PRUNEABLE_DIRECTORIES = %w[bin etc include lib sbin share Frameworks LinkedKegs var/homebrew/linked].map do |d|
- case d when "LinkedKegs" then HOMEBREW_LIBRARY/d else HOMEBREW_PREFIX/d end
+ PRUNEABLE_DIRECTORIES = %w[bin etc include lib sbin share Frameworks LinkedKegs var/homebrew/linked].map do |dir|
+ case dir
+ when "LinkedKegs"
+ HOMEBREW_LIBRARY/dir
+ else
+ HOMEBREW_PREFIX/dir
+ end
end
# These paths relative to the keg's share directory should always be real
@@ -113,9 +118,9 @@ class Keg
end
if Pathname.method_defined?(:to_path)
- alias_method :to_path, :to_s
+ alias to_path to_s
else
- alias_method :to_str, :to_s
+ alias to_str to_s
end
def inspect
@@ -125,7 +130,7 @@ class Keg
def ==(other)
instance_of?(other.class) && path == other.path
end
- alias_method :eql?, :==
+ alias eql? ==
def hash
path.hash
@@ -249,10 +254,10 @@ class Keg
def completion_installed?(shell)
dir = case shell
- when :bash then path.join("etc", "bash_completion.d")
- when :zsh then path.join("share", "zsh", "site-functions")
- when :fish then path.join("share", "fish", "vendor_completions.d")
- end
+ when :bash then path.join("etc", "bash_completion.d")
+ when :zsh then path.join("share", "zsh", "site-functions")
+ when :fish then path.join("share", "fish", "vendor_completions.d")
+ end
dir && dir.directory? && !dir.children.empty?
end
@@ -318,13 +323,13 @@ class Keg
when "locale/locale.alias" then :skip_file
when INFOFILE_RX then :info
when LOCALEDIR_RX then :mkpath
- when /^icons\/.*\/icon-theme\.cache$/ then :skip_file
+ when %r{^icons/.*/icon-theme\.cache$} then :skip_file
# all icons subfolders should also mkpath
- when /^icons\// then :mkpath
+ when %r{^icons/} then :mkpath
when /^zsh/ then :mkpath
when /^fish/ then :mkpath
# Lua, Lua51, Lua53 all need the same handling.
- when /^lua\// then :mkpath
+ when %r{^lua/} then :mkpath
when %r{^guile/} then :mkpath
when *SHARE_PATHS then :mkpath
else :link
@@ -362,7 +367,7 @@ class Keg
# the :link strategy. However, for Foo.framework and
# Foo.framework/Versions we have to use :mkpath so that multiple formulae
# can link their versions into it and `brew [un]link` works.
- if relative_path.to_s =~ /[^\/]*\.framework(\/Versions)?$/
+ if relative_path.to_s =~ %r{[^/]*\.framework(/Versions)?$}
:mkpath
else
:link
@@ -389,10 +394,9 @@ class Keg
opt_record.delete if opt_record.symlink? || opt_record.exist?
make_relative_symlink(opt_record, path, mode)
- if oldname_opt_record
- oldname_opt_record.delete
- make_relative_symlink(oldname_opt_record, path, mode)
- end
+ return unless oldname_opt_record
+ oldname_opt_record.delete
+ make_relative_symlink(oldname_opt_record, path, mode)
end
def delete_pyc_files!
@@ -418,18 +422,19 @@ class Keg
return
end
- if stat.directory?
- begin
- keg = Keg.for(src)
- rescue NotAKegError
- puts "Won't resolve conflicts for symlink #{dst} as it doesn't resolve into the Cellar" if ARGV.verbose?
- return
+ return unless stat.directory?
+ begin
+ keg = Keg.for(src)
+ rescue NotAKegError
+ if ARGV.verbose?
+ puts "Won't resolve conflicts for symlink #{dst} as it doesn't resolve into the Cellar"
end
-
- dst.unlink unless mode.dry_run
- keg.link_dir(src, mode) { :mkpath }
- return true
+ return
end
+
+ dst.unlink unless mode.dry_run
+ keg.link_dir(src, mode) { :mkpath }
+ true
end
def make_relative_symlink(dst, src, mode)
@@ -457,9 +462,8 @@ class Keg
dst.delete if mode.overwrite && (dst.exist? || dst.symlink?)
dst.make_relative_symlink(src)
rescue Errno::EEXIST => e
- if dst.exist?
- raise ConflictError.new(self, src.relative_path_from(path), dst, e)
- elsif dst.symlink?
+ raise ConflictError.new(self, src.relative_path_from(path), dst, e) if dst.exist?
+ if dst.symlink?
dst.unlink
retry
end