Skip to content

Commit

Permalink
Decouple pathname from bottles
Browse files Browse the repository at this point in the history
Pathname is one of the basic building block classes in Homebrew, and as
such it is preferrable that `require`ing it does not drag in other
Homebrew code; thus avoiding circular dependency situations. Its
dependency on bottles.rb gave it an implicit dependency on formula.rb,
among other things.

Signed-off-by: Jack Nagel <[email protected]>
  • Loading branch information
jacknagel committed Jul 6, 2012
1 parent 55bd678 commit a76bce6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Library/Homebrew/bottles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def bottle_native_regex
end

def bottle_regex
/(\.[a-z]+\.bottle\.(\d+\.)?tar\.gz)$/
Pathname::BOTTLE_EXTNAME_RX
end

def old_bottle_regex
/((\.[a-z]+)?[\.-]bottle\.tar\.gz)$/
Pathname::OLD_BOTTLE_EXTNAME_RX
end

def bottle_base_url
Expand Down
10 changes: 7 additions & 3 deletions Library/Homebrew/extend/pathname.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require 'pathname'
require 'bottles'
require 'mach'

# we enhance pathname to make our code more readable
class Pathname
include MachO

BOTTLE_EXTNAME_RX = /(\.[a-z]+\.bottle\.(\d+\.)?tar\.gz)$/
OLD_BOTTLE_EXTNAME_RX = /((\.[a-z]+)?[\.-]bottle\.tar\.gz)$/

def install *sources
results = []
sources.each do |src|
Expand Down Expand Up @@ -122,8 +124,10 @@ def cp dst
# extended to support common double extensions
alias extname_old extname
def extname
return $1 if to_s =~ bottle_regex
return $1 if to_s =~ old_bottle_regex
BOTTLE_EXTNAME_RX.match to_s
return $1 if $1
OLD_BOTTLE_EXTNAME_RX.match to_s
return $1 if $1
/(\.(tar|cpio)\.(gz|bz2|xz|Z))$/.match to_s
return $1 if $1
return File.extname(to_s)
Expand Down

0 comments on commit a76bce6

Please sign in to comment.