aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorAlyssa Ross2017-01-19 19:24:24 +0000
committerGitHub2017-01-19 19:24:24 +0000
commitd7c463ad2c036bd9917398069217f6cad0f5b326 (patch)
tree911faaafa8404187859906f6b457e9622e78840d /Library/Homebrew
parent0810039868f2fca0f69cbc6d869e53ae97129e98 (diff)
parent245944d359f366aaf511f133e11c98ec14cd50b1 (diff)
downloadbrew-d7c463ad2c036bd9917398069217f6cad0f5b326.tar.bz2
Merge pull request #1878 from alyssais/keg_cleanup
Simplify Keg class
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/keg.rb56
1 files changed, 7 insertions, 49 deletions
diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb
index 14eb0e3f3..837968615 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -174,6 +174,12 @@ class Keg
attr_reader :path, :name, :linked_keg_record, :opt_record
protected :path
+ extend Forwardable
+
+ def_delegators :path,
+ :to_s, :hash, :abv, :disk_usage, :file_count, :directory?, :exist?, :/,
+ :join, :rename, :find
+
def initialize(path)
path = path.resolved_path if path.to_s.start_with?("#{HOMEBREW_PREFIX}/opt/")
raise "#{path} is not a valid keg" unless path.parent.parent.realpath == HOMEBREW_CELLAR.realpath
@@ -184,19 +190,11 @@ class Keg
@opt_record = HOMEBREW_PREFIX/"opt/#{name}"
end
- def to_s
- path.to_s
- end
-
def rack
path.parent
end
- if Pathname.method_defined?(:to_path)
- alias to_path to_s
- else
- alias to_str to_s
- end
+ alias to_path to_s
def inspect
"#<#{self.class.name}:#{path}>"
@@ -207,30 +205,6 @@ class Keg
end
alias eql? ==
- def hash
- path.hash
- end
-
- def abv
- path.abv
- end
-
- def disk_usage
- path.disk_usage
- end
-
- def file_count
- path.file_count
- end
-
- def directory?
- path.directory?
- end
-
- def exist?
- path.exist?
- end
-
def empty_installation?
Pathname.glob("#{path}/**/*") do |file|
next if file.directory?
@@ -243,18 +217,6 @@ class Keg
true
end
- def /(other)
- path / other
- end
-
- def join(*args)
- path.join(*args)
- end
-
- def rename(*args)
- path.rename(*args)
- end
-
def linked?
linked_keg_record.symlink? &&
linked_keg_record.directory? &&
@@ -400,10 +362,6 @@ class Keg
end
end
- def find(*args, &block)
- path.find(*args, &block)
- end
-
def oldname_opt_record
@oldname_opt_record ||= if (opt_dir = HOMEBREW_PREFIX/"opt").directory?
opt_dir.subdirs.detect do |dir|