Create Utils::Curl module and explicitly include it.

This commit is contained in:
Markus Reiter 2020-10-10 15:23:03 +02:00
parent 318091cccc
commit ff653571b1
5 changed files with 274 additions and 263 deletions

View File

@ -11,6 +11,8 @@ require "lock_file"
require "mechanize/version" require "mechanize/version"
require "mechanize/http/content_disposition_parser" require "mechanize/http/content_disposition_parser"
require "utils/curl"
# @abstract Abstract superclass for all download strategies. # @abstract Abstract superclass for all download strategies.
# #
# @api private # @api private
@ -328,6 +330,8 @@ end
# #
# @api public # @api public
class CurlDownloadStrategy < AbstractFileDownloadStrategy class CurlDownloadStrategy < AbstractFileDownloadStrategy
include Utils::Curl
attr_reader :mirrors attr_reader :mirrors
def initialize(url, name, version, **meta) def initialize(url, name, version, **meta)

View File

@ -1,15 +0,0 @@
# typed: strict
module SharedAudits
def github(user, repo)
end
def gitlab(user, repo)
end
def bitbucket(user, repo)
end
def curl_output(*args, secrets: [], **options)
end
end

View File

@ -3,6 +3,13 @@
require "open3" require "open3"
module Utils
# Helper function for interacting with `curl`.
#
# @api private
module Curl
module_function
def curl_executable def curl_executable
@curl ||= [ @curl ||= [
ENV["HOMEBREW_CURL"], ENV["HOMEBREW_CURL"],
@ -47,7 +54,9 @@ def curl_args(*extra_args, show_output: false, user_agent: :default)
args + extra_args args + extra_args
end end
def curl_with_workarounds(*args, secrets: nil, print_stdout: nil, print_stderr: nil, verbose: nil, env: {}, **options) def curl_with_workarounds(
*args, secrets: nil, print_stdout: nil, print_stderr: nil, verbose: nil, env: {}, **options
)
command_options = { command_options = {
secrets: secrets, secrets: secrets,
print_stdout: print_stdout, print_stdout: print_stdout,
@ -118,7 +127,9 @@ def curl_download(*args, to: nil, partial: true, **options)
0 0
end end
curl("--location", "--remote-time", "--continue-at", continue_at.to_s, "--output", destination, *args, **options) curl(
"--location", "--remote-time", "--continue-at", continue_at.to_s, "--output", destination, *args, **options
)
end end
def curl_output(*args, **options) def curl_output(*args, **options)
@ -259,3 +270,8 @@ end
def http_status_ok?(status) def http_status_ok?(status)
(100..299).cover?(status.to_i) (100..299).cover?(status.to_i)
end end
end
end
# FIXME: Include `Utils::Curl` explicitly everywhere it is used.
include Utils::Curl # rubocop:disable Style/MixinUsage

View File

@ -7,6 +7,9 @@ require "utils/curl"
# #
# @api private # @api private
module SharedAudits module SharedAudits
include Utils::Curl
extend Utils::Curl
module_function module_function
def github_repo_data(user, repo) def github_repo_data(user, repo)

View File

@ -1,12 +1,15 @@
# typed: true # typed: true
# frozen_string_literal: true # frozen_string_literal: true
require "utils/curl"
require "utils/github" require "utils/github"
# Helper module for updating SPDX license data. # Helper module for updating SPDX license data.
# #
# @api private # @api private
module SPDX module SPDX
extend Utils::Curl
module_function module_function
DATA_PATH = (HOMEBREW_DATA_PATH/"spdx").freeze DATA_PATH = (HOMEBREW_DATA_PATH/"spdx").freeze