From e62fc26b9ce05aee374cc7e32ca37ba8bb46d36e Mon Sep 17 00:00:00 2001
From: Dominyk Tiller <dominyktiller@gmail.com>
Date: Wed, 10 Aug 2016 20:53:58 +0100
Subject: [PATCH] gpg_requirement: centralise logic in Gpg class

Removes the detection logic from the Requirement in favour of it living inside
the Gpg class & us calling it from there. It's a bit nicer & avoids us calling
Requirement code from outside of direct requirement handling & fulfillment.
---
 .../Homebrew/requirements/gpg_requirement.rb  | 19 ++-----------------
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/Library/Homebrew/requirements/gpg_requirement.rb b/Library/Homebrew/requirements/gpg_requirement.rb
index ef33a4fc55..bb41f0b0b1 100644
--- a/Library/Homebrew/requirements/gpg_requirement.rb
+++ b/Library/Homebrew/requirements/gpg_requirement.rb
@@ -1,27 +1,12 @@
 require "requirement"
+require "gpg"
 
 class GPGRequirement < Requirement
   fatal true
   default_formula "gnupg2"
 
-  satisfy(:build_env => false) { gpg2 || gpg }
-
   # MacGPG2/GPGTools installs GnuPG 2.0.x as a vanilla `gpg` symlink
   # pointing to `gpg2`, as do we. Ensure we're actually using a 2.0 `gpg`.
   # Temporarily, only support 2.0.x rather than the 2.1.x "modern" series.
-  def gpg
-    which_all("gpg").detect do |gpg|
-      gpg_short_version = Utils.popen_read(gpg, "--version")[/\d\.\d/, 0]
-      next unless gpg_short_version
-      Version.create(gpg_short_version.to_s) == Version.create("2.0")
-    end
-  end
-
-  def gpg2
-    which_all("gpg2").detect do |gpg2|
-      gpg2_short_version = Utils.popen_read(gpg2, "--version")[/\d\.\d/, 0]
-      next unless gpg2_short_version
-      Version.create(gpg2_short_version.to_s) == Version.create("2.0")
-    end
-  end
+  satisfy(:build_env => false) { Gpg.gpg2 || Gpg.gpg }
 end
-- 
GitLab