Merge pull request #793 from reitermarkus/refactoring-pathname

Merge Cask’s `Pathname` extension with Homebrew’s.
This commit is contained in:
Markus Reiter 2016-08-24 12:32:17 +02:00 committed by GitHub
commit fa19447a2d
9 changed files with 9 additions and 31 deletions

View File

@ -10,7 +10,7 @@ class Hbc::Container::Gzip < Hbc::Container::Base
def extract
Dir.mktmpdir do |unpack_dir|
@command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir])
@command.run!("/usr/bin/gunzip", args: ["--quiet", "--", Pathname.new(unpack_dir).join(@path.basename)])
@command.run!("/usr/bin/gunzip", args: ["--quiet", "--name", "--", Pathname.new(unpack_dir).join(@path.basename)])
extract_nested_inside(unpack_dir)
end

View File

@ -2,5 +2,5 @@
require "hbc/extend/hash"
require "hbc/extend/io"
require "hbc/extend/optparse"
require "hbc/extend/pathname"
require "extend/pathname"
require "hbc/extend/string"

View File

@ -1,19 +0,0 @@
require "pathname"
class Pathname
# extended to support common double extensions
def extname(path = to_s)
%r{(\.(dmg|tar|cpio|pax)\.(gz|bz2|lz|xz|Z|zip))$} =~ path
return Regexp.last_match(1) if Regexp.last_match(1)
File.extname(path)
end
# https://bugs.ruby-lang.org/issues/9915
if RUBY_VERSION == "2.0.0"
prepend Module.new {
def inspect
super.force_encoding(@path.encoding)
end
}
end
end

View File

@ -1,6 +1,5 @@
require "rubygems"
require "extend/pathname"
require "hbc/cask_dependencies"
require "hbc/staged"
require "hbc/verify"

View File

@ -13,7 +13,6 @@ project_root = Pathname.new(File.expand_path("../..", __FILE__))
$LOAD_PATH.unshift(File.expand_path("#{ENV['HOMEBREW_REPOSITORY']}/Library/Homebrew"))
require "global"
require "extend/pathname"
# add Homebrew-Cask to load path
$LOAD_PATH.push(project_root.join("lib").to_s)

View File

@ -154,7 +154,7 @@ describe Hbc::Installer do
dest_path = Hbc.caskroom.join("container-gzip", asset.version)
dest_path.must_be :directory?
file = Hbc.appdir.join("container-gzip--#{asset.version}")
file = Hbc.appdir.join("container")
file.must_be :file?
end

View File

@ -5,5 +5,5 @@ test_cask 'container-gzip' do
url TestHelper.local_binary_url('container.gz')
homepage 'https://example.com/container-gzip'
app 'container-gzip--1.2.3'
app 'container'
end

View File

@ -14,7 +14,6 @@ tap_root = Pathname.new(ENV["HOMEBREW_LIBRARY"]).join("Taps", "caskroom", "homeb
$LOAD_PATH.unshift(File.expand_path("#{ENV['HOMEBREW_REPOSITORY']}/Library/Homebrew"))
require "global"
require "extend/pathname"
# add Homebrew-Cask to load path
$LOAD_PATH.push(project_root.join("lib").to_s)

View File

@ -216,10 +216,10 @@ class Pathname
# extended to support common double extensions
def extname(path = to_s)
BOTTLE_EXTNAME_RX.match(path)
return $1 if $1
/(\.(tar|cpio|pax)\.(gz|bz2|lz|xz|Z))$/.match(path)
return $1 if $1
bottle_ext = path[BOTTLE_EXTNAME_RX, 1]
return bottle_ext if bottle_ext
archive_ext = path[/(\.(tar|cpio|pax)\.(gz|bz2|lz|xz|Z))$/, 1]
return archive_ext if archive_ext
File.extname(path)
end
@ -445,8 +445,8 @@ class Pathname
end
end
# https://bugs.ruby-lang.org/issues/9915
if RUBY_VERSION == "2.0.0"
# https://bugs.ruby-lang.org/issues/9915
prepend Module.new {
def inspect
super.force_encoding(@path.encoding)