keg: use Forwardable to methods delegated to #path

This commit is contained in:
Alyssa Ross 2017-01-18 22:21:22 +00:00
parent 34e13fc527
commit 245944d359

View File

@ -174,6 +174,12 @@ class Keg
attr_reader :path, :name, :linked_keg_record, :opt_record attr_reader :path, :name, :linked_keg_record, :opt_record
protected :path protected :path
extend Forwardable
def_delegators :path,
:to_s, :hash, :abv, :disk_usage, :file_count, :directory?, :exist?, :/,
:join, :rename, :find
def initialize(path) def initialize(path)
path = path.resolved_path if path.to_s.start_with?("#{HOMEBREW_PREFIX}/opt/") 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 raise "#{path} is not a valid keg" unless path.parent.parent.realpath == HOMEBREW_CELLAR.realpath
@ -184,10 +190,6 @@ class Keg
@opt_record = HOMEBREW_PREFIX/"opt/#{name}" @opt_record = HOMEBREW_PREFIX/"opt/#{name}"
end end
def to_s
path.to_s
end
def rack def rack
path.parent path.parent
end end
@ -203,30 +205,6 @@ class Keg
end end
alias eql? == 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? def empty_installation?
Pathname.glob("#{path}/**/*") do |file| Pathname.glob("#{path}/**/*") do |file|
next if file.directory? next if file.directory?
@ -239,18 +217,6 @@ class Keg
true true
end end
def /(other)
path / other
end
def join(*args)
path.join(*args)
end
def rename(*args)
path.rename(*args)
end
def linked? def linked?
linked_keg_record.symlink? && linked_keg_record.symlink? &&
linked_keg_record.directory? && linked_keg_record.directory? &&
@ -396,10 +362,6 @@ class Keg
end end
end end
def find(*args, &block)
path.find(*args, &block)
end
def oldname_opt_record def oldname_opt_record
@oldname_opt_record ||= if (opt_dir = HOMEBREW_PREFIX/"opt").directory? @oldname_opt_record ||= if (opt_dir = HOMEBREW_PREFIX/"opt").directory?
opt_dir.subdirs.detect do |dir| opt_dir.subdirs.detect do |dir|