Skip to content

Commit

Permalink
Merge pull request #1878 from alyssais/keg_cleanup
Browse files Browse the repository at this point in the history
Simplify Keg class
  • Loading branch information
alyssais authored Jan 19, 2017
2 parents 0810039 + 245944d commit d7c463a
Showing 1 changed file with 7 additions and 49 deletions.
56 changes: 7 additions & 49 deletions Library/Homebrew/keg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ def self.all
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
Expand All @@ -184,19 +190,11 @@ def initialize(path)
@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}>"
Expand All @@ -207,30 +205,6 @@ def ==(other)
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?
Expand All @@ -243,18 +217,6 @@ def empty_installation?
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? &&
Expand Down Expand Up @@ -400,10 +362,6 @@ def installed_dependents
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|
Expand Down

0 comments on commit d7c463a

Please sign in to comment.