Use ActiveSupport’s #second.
				
					
				
			This commit is contained in:
		
							parent
							
								
									72f350e757
								
							
						
					
					
						commit
						c4d418e126
					
				@ -5,9 +5,7 @@ end
 | 
				
			|||||||
std_trap = trap("INT") { exit! 130 } # no backtrace thanks
 | 
					std_trap = trap("INT") { exit! 130 } # no backtrace thanks
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# check ruby version before requiring any modules.
 | 
					# check ruby version before requiring any modules.
 | 
				
			||||||
RUBY_VERSION_SPLIT = RUBY_VERSION.split "."
 | 
					RUBY_X, RUBY_Y, = RUBY_VERSION.split(".").map(&:to_i)
 | 
				
			||||||
RUBY_X = RUBY_VERSION_SPLIT[0].to_i
 | 
					 | 
				
			||||||
RUBY_Y = RUBY_VERSION_SPLIT[1].to_i
 | 
					 | 
				
			||||||
if RUBY_X < 2 || (RUBY_X == 2 && RUBY_Y < 3)
 | 
					if RUBY_X < 2 || (RUBY_X == 2 && RUBY_Y < 3)
 | 
				
			||||||
  raise "Homebrew must be run under Ruby 2.3! You're running #{RUBY_VERSION}."
 | 
					  raise "Homebrew must be run under Ruby 2.3! You're running #{RUBY_VERSION}."
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -115,10 +115,8 @@ module Cask
 | 
				
			|||||||
        command.run!("/bin/launchctl", args: ["list"]).stdout.lines
 | 
					        command.run!("/bin/launchctl", args: ["list"]).stdout.lines
 | 
				
			||||||
               .map { |line| line.chomp.split("\t") }
 | 
					               .map { |line| line.chomp.split("\t") }
 | 
				
			||||||
               .map { |pid, state, id| [pid.to_i, state.to_i, id] }
 | 
					               .map { |pid, state, id| [pid.to_i, state.to_i, id] }
 | 
				
			||||||
               .select do |fields|
 | 
					               .select do |(pid, _, id)|
 | 
				
			||||||
                 next if fields[0].zero?
 | 
					                 pid.nonzero? && id.match?(/^#{Regexp.escape(bundle_id)}($|\.\d+)/)
 | 
				
			||||||
 | 
					 | 
				
			||||||
                 fields[2] =~ /^#{Regexp.escape(bundle_id)}($|\.\d+)/
 | 
					 | 
				
			||||||
               end
 | 
					               end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -89,19 +89,19 @@ module Cask
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def before_comma
 | 
					      def before_comma
 | 
				
			||||||
        version { split(",", 2)[0] }
 | 
					        version { split(",", 2).first }
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def after_comma
 | 
					      def after_comma
 | 
				
			||||||
        version { split(",", 2)[1] }
 | 
					        version { split(",", 2).second }
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def before_colon
 | 
					      def before_colon
 | 
				
			||||||
        version { split(":", 2)[0] }
 | 
					        version { split(":", 2).first }
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def after_colon
 | 
					      def after_colon
 | 
				
			||||||
        version { split(":", 2)[1] }
 | 
					        version { split(":", 2).second }
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def no_dividers
 | 
					      def no_dividers
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,7 @@ module Homebrew
 | 
				
			|||||||
                   .map { |d| Keg.new(d).version }
 | 
					                   .map { |d| Keg.new(d).version }
 | 
				
			||||||
                   .sort
 | 
					                   .sort
 | 
				
			||||||
                   .join(", ")
 | 
					                   .join(", ")
 | 
				
			||||||
    version = ARGV[1]
 | 
					    version = ARGV.second
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if !version || ARGV.named.length > 2
 | 
					    if !version || ARGV.named.length > 2
 | 
				
			||||||
      onoe usage
 | 
					      onoe usage
 | 
				
			||||||
 | 
				
			|||||||
@ -45,9 +45,9 @@ module Homebrew
 | 
				
			|||||||
    elsif ARGV.named.empty?
 | 
					    elsif ARGV.named.empty?
 | 
				
			||||||
      puts Tap.names
 | 
					      puts Tap.names
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      tap = Tap.fetch(ARGV.named[0])
 | 
					      tap = Tap.fetch(ARGV.named.first)
 | 
				
			||||||
      begin
 | 
					      begin
 | 
				
			||||||
        tap.install clone_target: ARGV.named[1],
 | 
					        tap.install clone_target: ARGV.named.second,
 | 
				
			||||||
                    force_auto_update: force_auto_update?,
 | 
					                    force_auto_update: force_auto_update?,
 | 
				
			||||||
                    full_clone: full_clone?,
 | 
					                    full_clone: full_clone?,
 | 
				
			||||||
                    quiet: ARGV.quieter?
 | 
					                    quiet: ARGV.quieter?
 | 
				
			||||||
 | 
				
			|||||||
@ -512,7 +512,7 @@ module Homebrew
 | 
				
			|||||||
      # Formulae names can legitimately be uppercase/lowercase/both.
 | 
					      # Formulae names can legitimately be uppercase/lowercase/both.
 | 
				
			||||||
      name = Regexp.new(formula.name, Regexp::IGNORECASE)
 | 
					      name = Regexp.new(formula.name, Regexp::IGNORECASE)
 | 
				
			||||||
      reason.sub!(name, "")
 | 
					      reason.sub!(name, "")
 | 
				
			||||||
      first_word = reason.split[0]
 | 
					      first_word = reason.split.first
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if reason =~ /\A[A-Z]/ && !reason.start_with?(*whitelist)
 | 
					      if reason =~ /\A[A-Z]/ && !reason.start_with?(*whitelist)
 | 
				
			||||||
        problem <<~EOS
 | 
					        problem <<~EOS
 | 
				
			||||||
@ -724,7 +724,7 @@ module Homebrew
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        version = Version.parse(stable.url)
 | 
					        version = Version.parse(stable.url)
 | 
				
			||||||
        if version >= Version.create("1.0")
 | 
					        if version >= Version.create("1.0")
 | 
				
			||||||
          minor_version = version.to_s.split(".", 3)[1].to_i
 | 
					          _, minor_version, = version.to_s.split(".", 3).map(&:to_i)
 | 
				
			||||||
          if minor_version.odd?
 | 
					          if minor_version.odd?
 | 
				
			||||||
            problem "#{stable.version} is a development release"
 | 
					            problem "#{stable.version} is a development release"
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
 | 
				
			|||||||
@ -120,7 +120,7 @@ module Homebrew
 | 
				
			|||||||
    # Expect exactly two named arguments: formula and tap
 | 
					    # Expect exactly two named arguments: formula and tap
 | 
				
			||||||
    raise UsageError if ARGV.named.length != 2
 | 
					    raise UsageError if ARGV.named.length != 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    destination_tap = Tap.fetch(ARGV.named[1])
 | 
					    destination_tap = Tap.fetch(ARGV.named.second)
 | 
				
			||||||
    odie "Cannot extract formula to homebrew/core!" if destination_tap.core_tap?
 | 
					    odie "Cannot extract formula to homebrew/core!" if destination_tap.core_tap?
 | 
				
			||||||
    destination_tap.install unless destination_tap.installed?
 | 
					    destination_tap.install unless destination_tap.installed?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -33,7 +33,7 @@ module Homebrew
 | 
				
			|||||||
    ).lines.first.chomp
 | 
					    ).lines.first.chomp
 | 
				
			||||||
    odie "Could not find any previous tags!" unless previous_tag
 | 
					    odie "Could not find any previous tags!" unless previous_tag
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    end_ref = ARGV.named[1] || "origin/master"
 | 
					    end_ref = ARGV.named.second || "origin/master"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [previous_tag, end_ref].each do |ref|
 | 
					    [previous_tag, end_ref].each do |ref|
 | 
				
			||||||
      next if quiet_system "git", "-C", HOMEBREW_REPOSITORY, "rev-parse", "--verify", "--quiet", ref
 | 
					      next if quiet_system "git", "-C", HOMEBREW_REPOSITORY, "rev-parse", "--verify", "--quiet", ref
 | 
				
			||||||
 | 
				
			|||||||
@ -61,7 +61,7 @@ module Homebrew
 | 
				
			|||||||
        Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp
 | 
					        Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp
 | 
				
			||||||
      elsif args.to_tag?
 | 
					      elsif args.to_tag?
 | 
				
			||||||
        tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname")
 | 
					        tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname")
 | 
				
			||||||
        previous_tag = tags.lines[1]
 | 
					        previous_tag = tags.lines.second
 | 
				
			||||||
        previous_tag ||= begin
 | 
					        previous_tag ||= begin
 | 
				
			||||||
          if (HOMEBREW_REPOSITORY/".git/shallow").exist?
 | 
					          if (HOMEBREW_REPOSITORY/".git/shallow").exist?
 | 
				
			||||||
            safe_system "git", "fetch", "--tags", "--depth=1"
 | 
					            safe_system "git", "fetch", "--tags", "--depth=1"
 | 
				
			||||||
@ -69,7 +69,7 @@ module Homebrew
 | 
				
			|||||||
          elsif OS.linux?
 | 
					          elsif OS.linux?
 | 
				
			||||||
            tags = Utils.popen_read("git tag --list | sort -rV")
 | 
					            tags = Utils.popen_read("git tag --list | sort -rV")
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
          tags.lines[1]
 | 
					          tags.lines.second
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
        previous_tag = previous_tag.to_s.chomp
 | 
					        previous_tag = previous_tag.to_s.chomp
 | 
				
			||||||
        odie "Could not find previous tag in:\n#{tags}" if previous_tag.empty?
 | 
					        odie "Could not find previous tag in:\n#{tags}" if previous_tag.empty?
 | 
				
			||||||
 | 
				
			|||||||
@ -105,7 +105,7 @@ module FormulaClassUnavailableErrorModule
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def format_list(class_list)
 | 
					  def format_list(class_list)
 | 
				
			||||||
    class_list.map { |klass| klass.name.split("::")[-1] }.join(", ")
 | 
					    class_list.map { |klass| klass.name.split("::").last }.join(", ")
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -417,7 +417,7 @@ class Formula
 | 
				
			|||||||
  def aliases
 | 
					  def aliases
 | 
				
			||||||
    @aliases ||= if tap
 | 
					    @aliases ||= if tap
 | 
				
			||||||
      tap.alias_reverse_table[full_name].to_a.map do |a|
 | 
					      tap.alias_reverse_table[full_name].to_a.map do |a|
 | 
				
			||||||
        a.split("/")[-1]
 | 
					        a.split("/").last
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      []
 | 
					      []
 | 
				
			||||||
@ -1371,7 +1371,7 @@ class Formula
 | 
				
			|||||||
  # an array of all {Formula} names
 | 
					  # an array of all {Formula} names
 | 
				
			||||||
  # @private
 | 
					  # @private
 | 
				
			||||||
  def self.names
 | 
					  def self.names
 | 
				
			||||||
    @names ||= (core_names + tap_names.map { |name| name.split("/")[-1] }).uniq.sort
 | 
					    @names ||= (core_names + tap_names.map { |name| name.split("/").last }).uniq.sort
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # an array of all {Formula} files
 | 
					  # an array of all {Formula} files
 | 
				
			||||||
@ -1462,7 +1462,7 @@ class Formula
 | 
				
			|||||||
  # an array of all aliases
 | 
					  # an array of all aliases
 | 
				
			||||||
  # @private
 | 
					  # @private
 | 
				
			||||||
  def self.aliases
 | 
					  def self.aliases
 | 
				
			||||||
    @aliases ||= (core_aliases + tap_aliases.map { |name| name.split("/")[-1] }).uniq.sort
 | 
					    @aliases ||= (core_aliases + tap_aliases.map { |name| name.split("/").last }).uniq.sort
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # an array of all aliases, , which the tap formulae have the fully-qualified name
 | 
					  # an array of all aliases, , which the tap formulae have the fully-qualified name
 | 
				
			||||||
 | 
				
			|||||||
@ -71,9 +71,7 @@ module Language
 | 
				
			|||||||
        rm_rf Dir[".cabal-sandbox/*packages.conf.d/"]
 | 
					        rm_rf Dir[".cabal-sandbox/*packages.conf.d/"]
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def install_cabal_package(*args)
 | 
					      def install_cabal_package(*args, **options)
 | 
				
			||||||
        options = args[-1].is_a?(Hash) ? args.pop : {}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        cabal_sandbox do
 | 
					        cabal_sandbox do
 | 
				
			||||||
          cabal_install_tools(*options[:using]) if options[:using]
 | 
					          cabal_install_tools(*options[:using]) if options[:using]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -17,8 +17,8 @@ class Tap
 | 
				
			|||||||
    when 1
 | 
					    when 1
 | 
				
			||||||
      user, repo = args.first.split("/", 2)
 | 
					      user, repo = args.first.split("/", 2)
 | 
				
			||||||
    when 2
 | 
					    when 2
 | 
				
			||||||
      user = args[0]
 | 
					      user = args.first
 | 
				
			||||||
      repo = args[1]
 | 
					      repo = args.second
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if [user, repo].any? { |part| part.nil? || part.include?("/") }
 | 
					    if [user, repo].any? { |part| part.nil? || part.include?("/") }
 | 
				
			||||||
 | 
				
			|||||||
@ -419,10 +419,10 @@ describe Cask::DSL, :cask do
 | 
				
			|||||||
      let(:token) { "with-installer-script" }
 | 
					      let(:token) { "with-installer-script" }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it "allows installer script to be specified" do
 | 
					      it "allows installer script to be specified" do
 | 
				
			||||||
        expect(cask.artifacts.to_a[0].path).to eq(Pathname("/usr/bin/true"))
 | 
					        expect(cask.artifacts.to_a.first.path).to eq(Pathname("/usr/bin/true"))
 | 
				
			||||||
        expect(cask.artifacts.to_a[0].args[:args]).to eq(["--flag"])
 | 
					        expect(cask.artifacts.to_a.first.args[:args]).to eq(["--flag"])
 | 
				
			||||||
        expect(cask.artifacts.to_a[1].path).to eq(Pathname("/usr/bin/false"))
 | 
					        expect(cask.artifacts.to_a.second.path).to eq(Pathname("/usr/bin/false"))
 | 
				
			||||||
        expect(cask.artifacts.to_a[1].args[:args]).to eq(["--flag"])
 | 
					        expect(cask.artifacts.to_a.second.args[:args]).to eq(["--flag"])
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -86,8 +86,8 @@ describe Patch do
 | 
				
			|||||||
      )
 | 
					      )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      expect(patches.length).to eq(2)
 | 
					      expect(patches.length).to eq(2)
 | 
				
			||||||
      expect(patches[0].strip).to eq(:p1)
 | 
					      expect(patches.first.strip).to eq(:p1)
 | 
				
			||||||
      expect(patches[1].strip).to eq(:p1)
 | 
					      expect(patches.second.strip).to eq(:p1)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it "can create patches from a :p0 hash" do
 | 
					    it "can create patches from a :p0 hash" do
 | 
				
			||||||
 | 
				
			|||||||
@ -53,8 +53,9 @@ RSpec.shared_context "integration test" do
 | 
				
			|||||||
  def command_id_from_args(args)
 | 
					  def command_id_from_args(args)
 | 
				
			||||||
    @command_count ||= 0
 | 
					    @command_count ||= 0
 | 
				
			||||||
    pretty_args = args.join(" ").gsub(TEST_TMPDIR, "@TMPDIR@")
 | 
					    pretty_args = args.join(" ").gsub(TEST_TMPDIR, "@TMPDIR@")
 | 
				
			||||||
    file_and_line = caller[1].sub(/(.*\d+):.*/, '\1')
 | 
					    file_and_line = caller.second
 | 
				
			||||||
                             .sub("#{HOMEBREW_LIBRARY_PATH}/test/", "")
 | 
					                          .sub(/(.*\d+):.*/, '\1')
 | 
				
			||||||
 | 
					                          .sub("#{HOMEBREW_LIBRARY_PATH}/test/", "")
 | 
				
			||||||
    "#{file_and_line}:brew #{pretty_args}:#{@command_count += 1}"
 | 
					    "#{file_and_line}:brew #{pretty_args}:#{@command_count += 1}"
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -54,7 +54,7 @@ module Utils
 | 
				
			|||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def resolve_version(bottle_file)
 | 
					      def resolve_version(bottle_file)
 | 
				
			||||||
        PkgVersion.parse receipt_path(bottle_file).split("/")[1]
 | 
					        PkgVersion.parse receipt_path(bottle_file).split("/").second
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      def formula_contents(bottle_file,
 | 
					      def formula_contents(bottle_file,
 | 
				
			||||||
 | 
				
			|||||||
@ -7,8 +7,8 @@ module Tty
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  def width
 | 
					  def width
 | 
				
			||||||
    @width ||= begin
 | 
					    @width ||= begin
 | 
				
			||||||
      width = `/bin/stty size 2>/dev/null`.split[1]
 | 
					      _, width = `/bin/stty size 2>/dev/null`.split
 | 
				
			||||||
      width = `/usr/bin/tput cols 2>/dev/null`.split[0] if width.to_i.zero?
 | 
					      width, = `/usr/bin/tput cols 2>/dev/null`.split if width.to_i.zero?
 | 
				
			||||||
      width ||= 80
 | 
					      width ||= 80
 | 
				
			||||||
      width.to_i
 | 
					      width.to_i
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
				
			|||||||
@ -351,7 +351,7 @@ class Version
 | 
				
			|||||||
    # e.g. https://github.com/JustArchi/ArchiSteamFarm/releases/download/2.3.2.0/ASF.zip
 | 
					    # e.g. https://github.com/JustArchi/ArchiSteamFarm/releases/download/2.3.2.0/ASF.zip
 | 
				
			||||||
    # e.g. https://people.gnome.org/~newren/eg/download/1.7.5.2/eg
 | 
					    # e.g. https://people.gnome.org/~newren/eg/download/1.7.5.2/eg
 | 
				
			||||||
    m = %r{/([rvV]_?)?(\d\.\d+(\.\d+){,2})}.match(spec_s)
 | 
					    m = %r{/([rvV]_?)?(\d\.\d+(\.\d+){,2})}.match(spec_s)
 | 
				
			||||||
    return m.captures[1] unless m.nil?
 | 
					    return m.captures.second unless m.nil?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # e.g. https://www.ijg.org/files/jpegsrc.v8d.tar.gz
 | 
					    # e.g. https://www.ijg.org/files/jpegsrc.v8d.tar.gz
 | 
				
			||||||
    m = /\.v(\d+[a-z]?)/.match(stem)
 | 
					    m = /\.v(\d+[a-z]?)/.match(stem)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user