From 52526c962b235e16da03415dd78cf911afcf8106 Mon Sep 17 00:00:00 2001 From: Uladzislau Shablinski Date: Tue, 1 Nov 2016 03:53:20 +0300 Subject: [PATCH] formula: add new methods * `Formula#linked?` returns true if formula linked * `Formula#optlinked?` returns true if formula linked to opt formula installed to the Cellar * `Formula#prefix_linked?` returns true if linked keg points to the prefix passed as an argument * `Formula#linked_version` to get linked version of the formula --- Library/Homebrew/formula.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index bae2e3314f..0c19805a3d 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -553,6 +553,28 @@ class Formula Pathname.new("#{HOMEBREW_CELLAR}/#{name}/#{v}") end + # Is the formula linked? + def linked? + linked_keg.symlink? + end + + # Is the formula linked to opt? + def optlinked? + opt_prefix.symlink? + end + + # Is formula's linked keg points to the prefix. + def prefix_linked?(v = pkg_version) + return false unless linked? + linked_keg.resolved_path == prefix(v) + end + + # {PkgVersion} of the linked keg for the formula. + def linked_version + return unless linked? + Keg.for(linked_keg).version + end + # The parent of the prefix; the named directory in the cellar containing all # installed versions of this software # @private