From 0ab750bf24dac2cb411d76c05a0edb9b1f1b9333 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 26 Sep 2016 01:44:51 +0200 Subject: [PATCH 1/4] Use `module_function` for commands. --- Library/Homebrew/.rubocop_todo.yml | 2 +- Library/Homebrew/build_environment.rb | 2 ++ Library/Homebrew/cmd/--cache.rb | 2 ++ Library/Homebrew/cmd/--cellar.rb | 2 ++ Library/Homebrew/cmd/--env.rb | 2 ++ Library/Homebrew/cmd/--prefix.rb | 2 ++ Library/Homebrew/cmd/--repository.rb | 2 ++ Library/Homebrew/cmd/--version.rb | 2 ++ Library/Homebrew/cmd/analytics.rb | 2 ++ Library/Homebrew/cmd/cat.rb | 2 ++ Library/Homebrew/cmd/cleanup.rb | 2 ++ Library/Homebrew/cmd/command.rb | 2 ++ Library/Homebrew/cmd/commands.rb | 5 +++-- Library/Homebrew/cmd/config.rb | 2 ++ Library/Homebrew/cmd/deps.rb | 2 ++ Library/Homebrew/cmd/desc.rb | 2 ++ Library/Homebrew/cmd/diy.rb | 2 ++ Library/Homebrew/cmd/doctor.rb | 2 ++ Library/Homebrew/cmd/fetch.rb | 6 ++++-- Library/Homebrew/cmd/gist-logs.rb | 2 ++ Library/Homebrew/cmd/help.rb | 5 +++-- Library/Homebrew/cmd/home.rb | 2 ++ Library/Homebrew/cmd/info.rb | 2 ++ Library/Homebrew/cmd/install.rb | 2 ++ Library/Homebrew/cmd/irb.rb | 2 ++ Library/Homebrew/cmd/leaves.rb | 2 ++ Library/Homebrew/cmd/link.rb | 5 +++-- Library/Homebrew/cmd/linkapps.rb | 5 +++-- Library/Homebrew/cmd/list.rb | 6 ++++-- Library/Homebrew/cmd/log.rb | 5 +++-- Library/Homebrew/cmd/migrate.rb | 2 ++ Library/Homebrew/cmd/missing.rb | 2 ++ Library/Homebrew/cmd/options.rb | 2 ++ Library/Homebrew/cmd/outdated.rb | 2 ++ Library/Homebrew/cmd/pin.rb | 2 ++ Library/Homebrew/cmd/postinstall.rb | 2 ++ Library/Homebrew/cmd/prune.rb | 2 ++ Library/Homebrew/cmd/readall.rb | 2 ++ Library/Homebrew/cmd/reinstall.rb | 2 ++ Library/Homebrew/cmd/search.rb | 2 ++ Library/Homebrew/cmd/sh.rb | 2 ++ Library/Homebrew/cmd/style.rb | 2 ++ Library/Homebrew/cmd/switch.rb | 2 ++ Library/Homebrew/cmd/tap-info.rb | 6 ++++-- Library/Homebrew/cmd/tap-pin.rb | 2 ++ Library/Homebrew/cmd/tap-unpin.rb | 2 ++ Library/Homebrew/cmd/tap.rb | 2 ++ Library/Homebrew/cmd/uninstall.rb | 2 ++ Library/Homebrew/cmd/unlink.rb | 2 ++ Library/Homebrew/cmd/unlinkapps.rb | 7 +++++-- Library/Homebrew/cmd/unpack.rb | 2 ++ Library/Homebrew/cmd/unpin.rb | 2 ++ Library/Homebrew/cmd/untap.rb | 2 ++ Library/Homebrew/cmd/update-report.rb | 9 +++++++-- Library/Homebrew/cmd/upgrade.rb | 2 ++ Library/Homebrew/cmd/uses.rb | 2 ++ .../Homebrew/dev-cmd/aspell-dictionaries.rb | 2 ++ Library/Homebrew/dev-cmd/audit.rb | 2 ++ .../Homebrew/dev-cmd/boneyard-formula-pr.rb | 2 ++ Library/Homebrew/dev-cmd/bottle.rb | 2 ++ Library/Homebrew/dev-cmd/bump-formula-pr.rb | 2 ++ Library/Homebrew/dev-cmd/create.rb | 2 ++ Library/Homebrew/dev-cmd/edit.rb | 2 ++ Library/Homebrew/dev-cmd/linkage.rb | 2 ++ Library/Homebrew/dev-cmd/man.rb | 10 ++++++++-- Library/Homebrew/dev-cmd/mirror.rb | 2 ++ Library/Homebrew/dev-cmd/pull.rb | 12 ++++++++++-- Library/Homebrew/dev-cmd/tap-readme.rb | 2 ++ Library/Homebrew/dev-cmd/test.rb | 2 ++ Library/Homebrew/dev-cmd/tests.rb | 2 ++ Library/Homebrew/dev-cmd/update-test.rb | 2 ++ Library/Homebrew/global.rb | 19 +++++++++++++------ Library/Homebrew/options.rb | 2 ++ Library/Homebrew/test/test_utils.rb | 2 +- Library/Homebrew/utils.rb | 16 +++++++++------- 75 files changed, 199 insertions(+), 39 deletions(-) diff --git a/Library/Homebrew/.rubocop_todo.yml b/Library/Homebrew/.rubocop_todo.yml index 4c6a4bbc55..6a31cdecd1 100644 --- a/Library/Homebrew/.rubocop_todo.yml +++ b/Library/Homebrew/.rubocop_todo.yml @@ -66,7 +66,7 @@ Metrics/BlockNesting: # Offense count: 19 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 366 + Max: 400 # Offense count: 2 # Configuration parameters: CountKeywordArgs. diff --git a/Library/Homebrew/build_environment.rb b/Library/Homebrew/build_environment.rb index b66aafcdf7..e3299fb943 100644 --- a/Library/Homebrew/build_environment.rb +++ b/Library/Homebrew/build_environment.rb @@ -32,6 +32,8 @@ module BuildEnvironmentDSL end module Homebrew + module_function + def build_env_keys(env) %w[ CC CXX LD OBJC OBJCXX diff --git a/Library/Homebrew/cmd/--cache.rb b/Library/Homebrew/cmd/--cache.rb index d73d0cce10..2c407cefe0 100644 --- a/Library/Homebrew/cmd/--cache.rb +++ b/Library/Homebrew/cmd/--cache.rb @@ -7,6 +7,8 @@ require "cmd/fetch" module Homebrew + module_function + def __cache if ARGV.named.empty? puts HOMEBREW_CACHE diff --git a/Library/Homebrew/cmd/--cellar.rb b/Library/Homebrew/cmd/--cellar.rb index e1c641ce1b..f35847ead6 100644 --- a/Library/Homebrew/cmd/--cellar.rb +++ b/Library/Homebrew/cmd/--cellar.rb @@ -7,6 +7,8 @@ #: without any sort of versioned directory as the last path. module Homebrew + module_function + def __cellar if ARGV.named.empty? puts HOMEBREW_CELLAR diff --git a/Library/Homebrew/cmd/--env.rb b/Library/Homebrew/cmd/--env.rb index 0feb338dc8..323964dad0 100644 --- a/Library/Homebrew/cmd/--env.rb +++ b/Library/Homebrew/cmd/--env.rb @@ -6,6 +6,8 @@ require "build_environment" require "utils/shell" module Homebrew + module_function + def __env ENV.activate_extensions! ENV.deps = ARGV.formulae if superenv? diff --git a/Library/Homebrew/cmd/--prefix.rb b/Library/Homebrew/cmd/--prefix.rb index 07b43693c6..c59830833b 100644 --- a/Library/Homebrew/cmd/--prefix.rb +++ b/Library/Homebrew/cmd/--prefix.rb @@ -5,6 +5,8 @@ #: Display the location in the cellar where is or would be installed. module Homebrew + module_function + def __prefix if ARGV.named.empty? puts HOMEBREW_PREFIX diff --git a/Library/Homebrew/cmd/--repository.rb b/Library/Homebrew/cmd/--repository.rb index b3ad8367a4..7a25aba1c1 100644 --- a/Library/Homebrew/cmd/--repository.rb +++ b/Library/Homebrew/cmd/--repository.rb @@ -8,6 +8,8 @@ require "tap" module Homebrew + module_function + def __repository if ARGV.named.empty? puts HOMEBREW_REPOSITORY diff --git a/Library/Homebrew/cmd/--version.rb b/Library/Homebrew/cmd/--version.rb index 9a571abe17..736048341c 100644 --- a/Library/Homebrew/cmd/--version.rb +++ b/Library/Homebrew/cmd/--version.rb @@ -2,6 +2,8 @@ #: Print the version number of Homebrew to standard output and exit. module Homebrew + module_function + def __version # As a special case, `--version` is implemented directly in `brew.rb`. This # file merely serves as a container for the documentation. It also catches diff --git a/Library/Homebrew/cmd/analytics.rb b/Library/Homebrew/cmd/analytics.rb index 649c537107..2efa5a2d23 100644 --- a/Library/Homebrew/cmd/analytics.rb +++ b/Library/Homebrew/cmd/analytics.rb @@ -9,6 +9,8 @@ #: Regenerate UUID used in Homebrew's analytics. module Homebrew + module_function + def analytics config_file = HOMEBREW_REPOSITORY/".git/config" diff --git a/Library/Homebrew/cmd/cat.rb b/Library/Homebrew/cmd/cat.rb index a2fbd2f00e..7439869d30 100644 --- a/Library/Homebrew/cmd/cat.rb +++ b/Library/Homebrew/cmd/cat.rb @@ -2,6 +2,8 @@ #: Display the source to . module Homebrew + module_function + def cat # do not "fix" this to support multiple arguments, the output would be # unparsable, if the user wants to cat multiple formula they can call diff --git a/Library/Homebrew/cmd/cleanup.rb b/Library/Homebrew/cmd/cleanup.rb index 6e0915c9a8..5b46e08724 100644 --- a/Library/Homebrew/cmd/cleanup.rb +++ b/Library/Homebrew/cmd/cleanup.rb @@ -15,6 +15,8 @@ require "cleanup" require "utils" module Homebrew + module_function + def cleanup if ARGV.named.empty? Cleanup.cleanup diff --git a/Library/Homebrew/cmd/command.rb b/Library/Homebrew/cmd/command.rb index b76468f621..39e8ba6fc4 100644 --- a/Library/Homebrew/cmd/command.rb +++ b/Library/Homebrew/cmd/command.rb @@ -4,6 +4,8 @@ require "commands" module Homebrew + module_function + def command abort "This command requires a command argument" if ARGV.empty? cmd = ARGV.first diff --git a/Library/Homebrew/cmd/commands.rb b/Library/Homebrew/cmd/commands.rb index 4fad764ca6..34f0b14e9d 100644 --- a/Library/Homebrew/cmd/commands.rb +++ b/Library/Homebrew/cmd/commands.rb @@ -5,6 +5,8 @@ #: With `--include-aliases`, the aliases of internal commands will be included. module Homebrew + module_function + def commands if ARGV.include? "--quiet" cmds = internal_commands + external_commands @@ -48,11 +50,10 @@ module Homebrew end.sort end - private - def find_internal_commands(directory) directory.children.each_with_object([]) do |f, cmds| cmds << f.basename.to_s.sub(/\.(?:rb|sh)$/, "") if f.file? end end + private_class_method :find_internal_commands end diff --git a/Library/Homebrew/cmd/config.rb b/Library/Homebrew/cmd/config.rb index b5f2502b03..daaa51f32b 100644 --- a/Library/Homebrew/cmd/config.rb +++ b/Library/Homebrew/cmd/config.rb @@ -6,6 +6,8 @@ require "system_config" module Homebrew + module_function + def config SystemConfig.dump_verbose_config end diff --git a/Library/Homebrew/cmd/deps.rb b/Library/Homebrew/cmd/deps.rb index acaf922d7b..a5089392fc 100644 --- a/Library/Homebrew/cmd/deps.rb +++ b/Library/Homebrew/cmd/deps.rb @@ -42,6 +42,8 @@ require "formula" require "ostruct" module Homebrew + module_function + def deps mode = OpenStruct.new( installed?: ARGV.include?("--installed"), diff --git a/Library/Homebrew/cmd/desc.rb b/Library/Homebrew/cmd/desc.rb index 9bb737e40a..3ef02288bd 100644 --- a/Library/Homebrew/cmd/desc.rb +++ b/Library/Homebrew/cmd/desc.rb @@ -12,6 +12,8 @@ require "descriptions" require "cmd/search" module Homebrew + module_function + def desc search_type = [] search_type << :either if ARGV.flag? "--search" diff --git a/Library/Homebrew/cmd/diy.rb b/Library/Homebrew/cmd/diy.rb index 95ec7fe35b..a8f6440df6 100644 --- a/Library/Homebrew/cmd/diy.rb +++ b/Library/Homebrew/cmd/diy.rb @@ -11,6 +11,8 @@ require "formula" module Homebrew + module_function + def diy path = Pathname.getwd diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb index 89f32dc25f..df4bba4192 100644 --- a/Library/Homebrew/cmd/doctor.rb +++ b/Library/Homebrew/cmd/doctor.rb @@ -8,6 +8,8 @@ require "diagnostic" module Homebrew + module_function + def doctor inject_dump_stats!(Diagnostic::Checks, /^check_*/) if ARGV.switch? "D" diff --git a/Library/Homebrew/cmd/fetch.rb b/Library/Homebrew/cmd/fetch.rb index 9c42eda236..f42f140a50 100644 --- a/Library/Homebrew/cmd/fetch.rb +++ b/Library/Homebrew/cmd/fetch.rb @@ -24,6 +24,8 @@ require "formula" module Homebrew + module_function + def fetch raise FormulaUnspecifiedError if ARGV.named.empty? @@ -93,8 +95,6 @@ module Homebrew opoo "Patch reports different #{e.hash_type}: #{e.expected}" end - private - def retry_fetch?(f) @fetch_failed ||= Set.new if ARGV.include?("--retry") && @fetch_failed.add?(f) @@ -106,6 +106,7 @@ module Homebrew false end end + private_class_method :retry_fetch? def fetch_fetchable(f) f.clear_cache if ARGV.force? @@ -126,4 +127,5 @@ module Homebrew f.verify_download_integrity(download) end + private_class_method :fetch_fetchable end diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index 200ad9fb5e..e55eefc170 100644 --- a/Library/Homebrew/cmd/gist-logs.rb +++ b/Library/Homebrew/cmd/gist-logs.rb @@ -15,6 +15,8 @@ require "stringio" require "socket" module Homebrew + module_function + def gistify_logs(f) files = load_logs(f.logs) build_time = f.logs.ctime diff --git a/Library/Homebrew/cmd/help.rb b/Library/Homebrew/cmd/help.rb index 2a814b90ba..c533885add 100644 --- a/Library/Homebrew/cmd/help.rb +++ b/Library/Homebrew/cmd/help.rb @@ -34,6 +34,8 @@ EOS require "commands" module Homebrew + module_function + def help(cmd = nil, flags = {}) # Resolve command aliases and find file containing the implementation. if cmd @@ -69,8 +71,6 @@ module Homebrew exit 0 end - private - def command_help(path) help_lines = path.read.lines.grep(/^#:/) if help_lines.empty? @@ -86,4 +86,5 @@ module Homebrew end.join.strip end end + private_class_method :command_help end diff --git a/Library/Homebrew/cmd/home.rb b/Library/Homebrew/cmd/home.rb index 0c3009545c..50f3936e8c 100644 --- a/Library/Homebrew/cmd/home.rb +++ b/Library/Homebrew/cmd/home.rb @@ -5,6 +5,8 @@ #: Open 's homepage in a browser. module Homebrew + module_function + def home if ARGV.named.empty? exec_browser HOMEBREW_WWW diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 6f242039cc..857f1090e2 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -25,6 +25,8 @@ require "tab" require "utils/json" module Homebrew + module_function + def info # eventually we'll solidify an API, but we'll keep old versions # awhile around for compatibility diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 8a83232521..328df07ce0 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -64,6 +64,8 @@ require "hardware" require "development_tools" module Homebrew + module_function + def install raise FormulaUnspecifiedError if ARGV.named.empty? diff --git a/Library/Homebrew/cmd/irb.rb b/Library/Homebrew/cmd/irb.rb index 1db0855bbf..d162e3f4a5 100644 --- a/Library/Homebrew/cmd/irb.rb +++ b/Library/Homebrew/cmd/irb.rb @@ -19,6 +19,8 @@ class String end module Homebrew + module_function + def irb if ARGV.include? "--examples" puts "'v8'.f # => instance of the v8 formula" diff --git a/Library/Homebrew/cmd/leaves.rb b/Library/Homebrew/cmd/leaves.rb index 37e379d49e..4038aee4c3 100644 --- a/Library/Homebrew/cmd/leaves.rb +++ b/Library/Homebrew/cmd/leaves.rb @@ -6,6 +6,8 @@ require "tab" require "set" module Homebrew + module_function + def leaves installed = Formula.installed deps_of_installed = Set.new diff --git a/Library/Homebrew/cmd/link.rb b/Library/Homebrew/cmd/link.rb index 6486e6f185..a8612865b4 100644 --- a/Library/Homebrew/cmd/link.rb +++ b/Library/Homebrew/cmd/link.rb @@ -15,6 +15,8 @@ require "ostruct" module Homebrew + module_function + def link raise KegUnspecifiedError if ARGV.named.empty? @@ -71,11 +73,10 @@ module Homebrew end end - private - def keg_only?(rack) Formulary.from_rack(rack).keg_only? rescue FormulaUnavailableError, TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError false end + private_class_method :keg_only? end diff --git a/Library/Homebrew/cmd/linkapps.rb b/Library/Homebrew/cmd/linkapps.rb index c7685855f3..4f46362cce 100644 --- a/Library/Homebrew/cmd/linkapps.rb +++ b/Library/Homebrew/cmd/linkapps.rb @@ -11,6 +11,8 @@ require "keg" require "formula" module Homebrew + module_function + def linkapps target_dir = linkapps_target(local: ARGV.include?("--local")) @@ -55,10 +57,9 @@ module Homebrew end end - private - def linkapps_target(opts = {}) local = opts.fetch(:local, false) Pathname.new(local ? "~/Applications" : "/Applications").expand_path end + private_class_method :linkapps_target end diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index d2eebb5f1b..b6bee87fb7 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -22,6 +22,8 @@ require "metafiles" require "formula" module Homebrew + module_function + def list # Use of exec means we don't explicitly exit list_unbrewed if ARGV.flag? "--unbrewed" @@ -58,8 +60,6 @@ module Homebrew end end - private - UNBREWED_EXCLUDE_FILES = %w[.DS_Store].freeze UNBREWED_EXCLUDE_PATHS = %w[ .github/* @@ -101,6 +101,7 @@ module Homebrew cd HOMEBREW_PREFIX exec "find", *args end + private_class_method :list_unbrewed def filtered_list names = if ARGV.named.empty? @@ -127,6 +128,7 @@ module Homebrew end end end + private_class_method :filtered_list end class PrettyListing diff --git a/Library/Homebrew/cmd/log.rb b/Library/Homebrew/cmd/log.rb index 9492c1e1ed..734460e887 100644 --- a/Library/Homebrew/cmd/log.rb +++ b/Library/Homebrew/cmd/log.rb @@ -5,6 +5,8 @@ require "formula" module Homebrew + module_function + def log if ARGV.named.empty? cd HOMEBREW_REPOSITORY @@ -16,8 +18,6 @@ module Homebrew end end - private - def git_log(path = nil) if File.exist? "#{`git rev-parse --show-toplevel`.chomp}/.git/shallow" opoo <<-EOS.undent @@ -29,4 +29,5 @@ module Homebrew args += ["--", path] unless path.nil? exec "git", "log", *args end + private_class_method :git_log end diff --git a/Library/Homebrew/cmd/migrate.rb b/Library/Homebrew/cmd/migrate.rb index 27ca5261f9..2726b14800 100644 --- a/Library/Homebrew/cmd/migrate.rb +++ b/Library/Homebrew/cmd/migrate.rb @@ -8,6 +8,8 @@ require "migrator" module Homebrew + module_function + def migrate raise FormulaUnspecifiedError if ARGV.named.empty? diff --git a/Library/Homebrew/cmd/missing.rb b/Library/Homebrew/cmd/missing.rb index bbd514223f..525461108b 100644 --- a/Library/Homebrew/cmd/missing.rb +++ b/Library/Homebrew/cmd/missing.rb @@ -7,6 +7,8 @@ require "tab" require "diagnostic" module Homebrew + module_function + def missing return unless HOMEBREW_CELLAR.exist? diff --git a/Library/Homebrew/cmd/options.rb b/Library/Homebrew/cmd/options.rb index 690acd0169..843d3a1ee8 100644 --- a/Library/Homebrew/cmd/options.rb +++ b/Library/Homebrew/cmd/options.rb @@ -12,6 +12,8 @@ require "formula" require "options" module Homebrew + module_function + def options if ARGV.include? "--all" puts_options Formula.to_a diff --git a/Library/Homebrew/cmd/outdated.rb b/Library/Homebrew/cmd/outdated.rb index a6fa1f0036..5dc77857ea 100644 --- a/Library/Homebrew/cmd/outdated.rb +++ b/Library/Homebrew/cmd/outdated.rb @@ -21,6 +21,8 @@ require "formula" require "keg" module Homebrew + module_function + def outdated formulae = if ARGV.resolved_formulae.empty? Formula.installed diff --git a/Library/Homebrew/cmd/pin.rb b/Library/Homebrew/cmd/pin.rb index a54ef6e7bf..c5087f6d4c 100644 --- a/Library/Homebrew/cmd/pin.rb +++ b/Library/Homebrew/cmd/pin.rb @@ -5,6 +5,8 @@ require "formula" module Homebrew + module_function + def pin raise FormulaUnspecifiedError if ARGV.named.empty? diff --git a/Library/Homebrew/cmd/postinstall.rb b/Library/Homebrew/cmd/postinstall.rb index e0bd8e31b1..1e205e65de 100644 --- a/Library/Homebrew/cmd/postinstall.rb +++ b/Library/Homebrew/cmd/postinstall.rb @@ -4,6 +4,8 @@ require "sandbox" module Homebrew + module_function + def postinstall ARGV.resolved_formulae.each { |f| run_post_install(f) if f.post_install_defined? } end diff --git a/Library/Homebrew/cmd/prune.rb b/Library/Homebrew/cmd/prune.rb index 83979064a1..e2e6d77b8e 100644 --- a/Library/Homebrew/cmd/prune.rb +++ b/Library/Homebrew/cmd/prune.rb @@ -12,6 +12,8 @@ require "cmd/tap" require "cmd/unlinkapps" module Homebrew + module_function + def prune ObserverPathnameExtension.reset_counts! diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb index e77e688652..7c1a085c9b 100644 --- a/Library/Homebrew/cmd/readall.rb +++ b/Library/Homebrew/cmd/readall.rb @@ -9,6 +9,8 @@ require "readall" module Homebrew + module_function + def readall if ARGV.include?("--syntax") ruby_files = [] diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index bda6022bfd..618835d744 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -5,6 +5,8 @@ require "formula_installer" require "development_tools" module Homebrew + module_function + def reinstall FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 5342b23b6e..8d6e5ad7c3 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -21,6 +21,8 @@ require "official_taps" require "descriptions" module Homebrew + module_function + SEARCH_ERROR_QUEUE = Queue.new def search diff --git a/Library/Homebrew/cmd/sh.rb b/Library/Homebrew/cmd/sh.rb index 11f57b6601..09e7f435e5 100644 --- a/Library/Homebrew/cmd/sh.rb +++ b/Library/Homebrew/cmd/sh.rb @@ -9,6 +9,8 @@ require "extend/ENV" require "formula" module Homebrew + module_function + def sh ENV.activate_extensions! diff --git a/Library/Homebrew/cmd/style.rb b/Library/Homebrew/cmd/style.rb index e666eb2007..9538b890a9 100644 --- a/Library/Homebrew/cmd/style.rb +++ b/Library/Homebrew/cmd/style.rb @@ -17,6 +17,8 @@ require "utils" require "utils/json" module Homebrew + module_function + def style target = if ARGV.named.empty? nil diff --git a/Library/Homebrew/cmd/switch.rb b/Library/Homebrew/cmd/switch.rb index a44514880a..6eed1fd966 100644 --- a/Library/Homebrew/cmd/switch.rb +++ b/Library/Homebrew/cmd/switch.rb @@ -6,6 +6,8 @@ require "keg" require "cmd/link" module Homebrew + module_function + def switch if ARGV.named.length != 2 onoe "Usage: brew switch " diff --git a/Library/Homebrew/cmd/tap-info.rb b/Library/Homebrew/cmd/tap-info.rb index 432d512873..71a98813d5 100644 --- a/Library/Homebrew/cmd/tap-info.rb +++ b/Library/Homebrew/cmd/tap-info.rb @@ -18,6 +18,8 @@ require "tap" module Homebrew + module_function + def tap_info if ARGV.include? "--installed" taps = Tap @@ -34,8 +36,6 @@ module Homebrew end end - private - def print_tap_info(taps) if taps.none? tap_count = 0 @@ -80,8 +80,10 @@ module Homebrew end end end + private_class_method :print_tap_info def print_tap_json(taps) puts Utils::JSON.dump(taps.map(&:to_hash)) end + private_class_method :print_tap_json end diff --git a/Library/Homebrew/cmd/tap-pin.rb b/Library/Homebrew/cmd/tap-pin.rb index 74e9fae3f3..41957f2652 100644 --- a/Library/Homebrew/cmd/tap-pin.rb +++ b/Library/Homebrew/cmd/tap-pin.rb @@ -5,6 +5,8 @@ require "tap" module Homebrew + module_function + def tap_pin ARGV.named.each do |name| tap = Tap.fetch(name) diff --git a/Library/Homebrew/cmd/tap-unpin.rb b/Library/Homebrew/cmd/tap-unpin.rb index 7ea2831f29..05bfc7c8b9 100644 --- a/Library/Homebrew/cmd/tap-unpin.rb +++ b/Library/Homebrew/cmd/tap-unpin.rb @@ -4,6 +4,8 @@ require "tap" module Homebrew + module_function + def tap_unpin ARGV.named.each do |name| tap = Tap.fetch(name) diff --git a/Library/Homebrew/cmd/tap.rb b/Library/Homebrew/cmd/tap.rb index 8ad63e4ba8..5b4ed24759 100644 --- a/Library/Homebrew/cmd/tap.rb +++ b/Library/Homebrew/cmd/tap.rb @@ -34,6 +34,8 @@ require "tap" module Homebrew + module_function + def tap if ARGV.include? "--repair" Tap.each(&:link_manpages) diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb index f4ca8ff87f..8bcfc31fbb 100644 --- a/Library/Homebrew/cmd/uninstall.rb +++ b/Library/Homebrew/cmd/uninstall.rb @@ -9,6 +9,8 @@ require "formula" require "migrator" module Homebrew + module_function + def uninstall raise KegUnspecifiedError if ARGV.named.empty? diff --git a/Library/Homebrew/cmd/unlink.rb b/Library/Homebrew/cmd/unlink.rb index adf0917094..a105f9c56e 100644 --- a/Library/Homebrew/cmd/unlink.rb +++ b/Library/Homebrew/cmd/unlink.rb @@ -9,6 +9,8 @@ require "ostruct" module Homebrew + module_function + def unlink raise KegUnspecifiedError if ARGV.named.empty? diff --git a/Library/Homebrew/cmd/unlinkapps.rb b/Library/Homebrew/cmd/unlinkapps.rb index fc53470ec7..0df6de929f 100644 --- a/Library/Homebrew/cmd/unlinkapps.rb +++ b/Library/Homebrew/cmd/unlinkapps.rb @@ -12,19 +12,20 @@ require "cmd/linkapps" module Homebrew + module_function + def unlinkapps target_dir = linkapps_target(local: ARGV.include?("--local")) unlinkapps_from_dir(target_dir, dry_run: ARGV.dry_run?) end - private - def unlinkapps_prune(opts = {}) opts = opts.merge(prune: true) unlinkapps_from_dir(linkapps_target(local: false), opts) unlinkapps_from_dir(linkapps_target(local: true), opts) end + private_class_method :unlinkapps_prune def unlinkapps_from_dir(target_dir, opts = {}) return unless target_dir.directory? @@ -57,6 +58,7 @@ module Homebrew puts "Unlinked #{n} app#{plural(n)} from #{target_dir}" end end + private_class_method :unlinkapps_from_dir UNLINKAPPS_PREFIXES = %W[ #{HOMEBREW_CELLAR}/ @@ -76,4 +78,5 @@ module Homebrew ARGV.kegs.any? { |keg| app.start_with?("#{keg}/", "#{keg.opt_record}/") } end end + private_class_method :unlinkapps_unlink? end diff --git a/Library/Homebrew/cmd/unpack.rb b/Library/Homebrew/cmd/unpack.rb index 1a3044c2e6..6f4caea189 100644 --- a/Library/Homebrew/cmd/unpack.rb +++ b/Library/Homebrew/cmd/unpack.rb @@ -13,6 +13,8 @@ require "stringio" require "formula" module Homebrew + module_function + def unpack formulae = ARGV.formulae raise FormulaUnspecifiedError if formulae.empty? diff --git a/Library/Homebrew/cmd/unpin.rb b/Library/Homebrew/cmd/unpin.rb index 4eb476bdf6..a669df1ec4 100644 --- a/Library/Homebrew/cmd/unpin.rb +++ b/Library/Homebrew/cmd/unpin.rb @@ -5,6 +5,8 @@ require "formula" module Homebrew + module_function + def unpin raise FormulaUnspecifiedError if ARGV.named.empty? diff --git a/Library/Homebrew/cmd/untap.rb b/Library/Homebrew/cmd/untap.rb index be91191b50..0d363b7b58 100644 --- a/Library/Homebrew/cmd/untap.rb +++ b/Library/Homebrew/cmd/untap.rb @@ -4,6 +4,8 @@ require "tap" module Homebrew + module_function + def untap raise "Usage is `brew untap `" if ARGV.empty? diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 18f2f370ca..84faf62896 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -10,6 +10,8 @@ require "cleanup" require "utils" module Homebrew + module_function + def update_preinstall_header @header_already_printed ||= begin ohai "Auto-updated Homebrew!" if ARGV.include?("--preinstall") @@ -106,11 +108,10 @@ module Homebrew end end - private - def shorten_revision(revision) Utils.popen_read("git", "-C", HOMEBREW_REPOSITORY, "rev-parse", "--short", revision).chomp end + private_class_method :shorten_revision def install_core_tap_if_necessary core_tap = CoreTap.instance @@ -120,6 +121,7 @@ module Homebrew ENV["HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_CORE"] = revision ENV["HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_CORE"] = revision end + private_class_method :install_core_tap_if_necessary def migrate_legacy_cache_if_necessary legacy_cache = Pathname.new "/Library/Caches/Homebrew" @@ -174,6 +176,7 @@ module Homebrew end end end + private_class_method :migrate_legacy_cache_if_necessary def migrate_legacy_repository_if_necessary return unless HOMEBREW_PREFIX.to_s == "/usr/local" @@ -292,6 +295,7 @@ module Homebrew EOS $stderr.puts e.backtrace end + private_class_method :migrate_legacy_repository_if_necessary def link_completions_and_docs(repository = HOMEBREW_REPOSITORY) command = "brew update" @@ -309,6 +313,7 @@ module Homebrew #{e} EOS end + private_class_method :link_completions_and_docs end class Reporter diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index f2c3799aba..40805b4ca6 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -18,6 +18,8 @@ require "cleanup" require "development_tools" module Homebrew + module_function + def upgrade FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 79b57eb235..4acf1b9f1f 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -23,6 +23,8 @@ require "formula" # The intersection is harder to achieve with shell tools. module Homebrew + module_function + def uses raise FormulaUnspecifiedError if ARGV.named.empty? diff --git a/Library/Homebrew/dev-cmd/aspell-dictionaries.rb b/Library/Homebrew/dev-cmd/aspell-dictionaries.rb index cbb88ffe56..86ad037ce6 100644 --- a/Library/Homebrew/dev-cmd/aspell-dictionaries.rb +++ b/Library/Homebrew/dev-cmd/aspell-dictionaries.rb @@ -7,6 +7,8 @@ require "resource" require "formula" module Homebrew + module_function + def aspell_dictionaries dict_url = "http://ftpmirror.gnu.org/aspell/dict" dict_mirror = "https://ftp.gnu.org/gnu/aspell/dict" diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 9d7a3ba923..4a86f4c045 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -37,6 +37,8 @@ require "cmd/style" require "date" module Homebrew + module_function + def audit Homebrew.inject_dump_stats!(FormulaAuditor, /^audit_/) if ARGV.switch? "D" diff --git a/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb b/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb index 890c9c4a08..a0739dbe93 100644 --- a/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb @@ -19,6 +19,8 @@ rescue LoadError end module Homebrew + module_function + def boneyard_formula_pr local_only = ARGV.include?("--local") formula = ARGV.formulae.first diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 83e40f25d2..a087a5e4cc 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -41,6 +41,8 @@ EOS MAXIMUM_STRING_MATCHES = 100 module Homebrew + module_function + def keg_contain?(string, keg, ignores) @put_string_exists_header, @put_filenames = nil diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 31e9cd2c11..32e4b52a2b 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -35,6 +35,8 @@ require "formula" module Homebrew + module_function + def inreplace_pairs(path, replacement_pairs) if ARGV.dry_run? contents = path.open("r") { |f| Formulary.ensure_utf8_encoding(f).read } diff --git a/Library/Homebrew/dev-cmd/create.rb b/Library/Homebrew/dev-cmd/create.rb index 19fd251b70..11544dbefe 100644 --- a/Library/Homebrew/dev-cmd/create.rb +++ b/Library/Homebrew/dev-cmd/create.rb @@ -24,6 +24,8 @@ require "digest" require "erb" module Homebrew + module_function + # Create a formula from a tarball URL def create # Allow searching MacPorts or Fink. diff --git a/Library/Homebrew/dev-cmd/edit.rb b/Library/Homebrew/dev-cmd/edit.rb index 2d2a5ec082..df5bc06058 100644 --- a/Library/Homebrew/dev-cmd/edit.rb +++ b/Library/Homebrew/dev-cmd/edit.rb @@ -7,6 +7,8 @@ require "formula" module Homebrew + module_function + def edit unless (HOMEBREW_REPOSITORY/".git").directory? raise <<-EOS.undent diff --git a/Library/Homebrew/dev-cmd/linkage.rb b/Library/Homebrew/dev-cmd/linkage.rb index 993420c024..44e0f224ee 100644 --- a/Library/Homebrew/dev-cmd/linkage.rb +++ b/Library/Homebrew/dev-cmd/linkage.rb @@ -13,6 +13,8 @@ require "os/mac/linkage_checker" module Homebrew + module_function + def linkage ARGV.kegs.each do |keg| ohai "Checking #{keg.name} linkage" if ARGV.kegs.size > 1 diff --git a/Library/Homebrew/dev-cmd/man.rb b/Library/Homebrew/dev-cmd/man.rb index d34d559f76..8e645d4014 100644 --- a/Library/Homebrew/dev-cmd/man.rb +++ b/Library/Homebrew/dev-cmd/man.rb @@ -12,6 +12,8 @@ require "erb" require "ostruct" module Homebrew + module_function + SOURCE_PATH = HOMEBREW_LIBRARY_PATH/"manpages" TARGET_MAN_PATH = HOMEBREW_REPOSITORY/"manpages" TARGET_DOC_PATH = HOMEBREW_REPOSITORY/"docs" @@ -32,8 +34,6 @@ module Homebrew end end - private - def regenerate_man_pages Homebrew.install_gem_setup_path! "ronn" @@ -44,6 +44,7 @@ module Homebrew cask_markup = (HOMEBREW_LIBRARY/"Homebrew/manpages/brew-cask.1.md").read convert_man_page(cask_markup, TARGET_MAN_PATH/"brew-cask.1") end + private_class_method :regenerate_man_pages def path_glob_commands(glob) Pathname.glob(glob) @@ -56,6 +57,7 @@ module Homebrew end .reject { |s| s.strip.empty? || s.include?("@hide_from_man_page") } end + private_class_method :path_glob_commands def build_man_page template = (SOURCE_PATH/"brew.1.md.erb").read @@ -73,11 +75,13 @@ module Homebrew ERB.new(template, nil, ">").result(variables.instance_eval { binding }) end + private_class_method :build_man_page def sort_key_for_path(path) # Options after regular commands (`~` comes after `z` in ASCII table). path.basename.to_s.sub(/\.(rb|sh)$/, "").sub(/^--/, "~~") end + private_class_method :sort_key_for_path def convert_man_page(markup, target) manual = target.basename(".1") @@ -110,6 +114,7 @@ module Homebrew target.atomic_write ronn.read end end + private_class_method :convert_man_page def target_path_to_format(target) case target.basename @@ -119,4 +124,5 @@ module Homebrew odie "Failed to infer output format from '#{target.basename}'." end end + private_class_method :target_path_to_format end diff --git a/Library/Homebrew/dev-cmd/mirror.rb b/Library/Homebrew/dev-cmd/mirror.rb index 9966163f8f..bd5868726f 100644 --- a/Library/Homebrew/dev-cmd/mirror.rb +++ b/Library/Homebrew/dev-cmd/mirror.rb @@ -3,6 +3,8 @@ #: Reuploads the stable URL for a formula to Bintray to use it as a mirror. module Homebrew + module_function + def mirror odie "This command requires at least formula argument!" if ARGV.named.empty? diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index 857c55993d..d64ebd4d17 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -40,6 +40,8 @@ require "version" require "pkg_version" module Homebrew + module_function + def pull odie "You meant `git pull --rebase`." if ARGV[0] == "--rebase" @@ -235,8 +237,6 @@ module Homebrew str.force_encoding("UTF-8") if str.respond_to?(:force_encoding) end - private - def publish_changed_formula_bottles(_tap, changed_formulae_names) if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"] raise "Need to load formulae to publish them!" @@ -257,10 +257,12 @@ module Homebrew end published end + private_class_method :publish_changed_formula_bottles def pull_patch(url, description = nil) PatchPuller.new(url, description).pull_patch end + private_class_method :pull_patch class PatchPuller attr_reader :base_url @@ -340,6 +342,7 @@ module Homebrew end { files: files, formulae: formulae, others: others } end + private_class_method :files_changed_in_patch # Get current formula versions without loading formula definition in this process # Returns info as a hash (type => version), for pull.rb's internal use @@ -356,6 +359,7 @@ module Homebrew end versions end + private_class_method :current_versions_from_info_external def subject_for_bump(formula, old, new) if old[:nonexistent] @@ -395,10 +399,12 @@ module Homebrew end subject end + private_class_method :subject_for_bump def pbcopy(text) Utils.popen_write("pbcopy") { |io| io.write text } end + private_class_method :pbcopy # Publishes the current bottle files for a given formula to Bintray def publish_bottle_file_on_bintray(f, creds) @@ -415,6 +421,7 @@ module Homebrew "-d", '{"publish_wait_for_secs": 0}', "https://api.bintray.com/content/homebrew/#{repo}/#{package}/#{version}/publish" end + private_class_method :publish_bottle_file_on_bintray # Formula info drawn from an external "brew info --json" call class FormulaInfoFromJson @@ -575,4 +582,5 @@ module Homebrew end end end + private_class_method :verify_bintray_published end diff --git a/Library/Homebrew/dev-cmd/tap-readme.rb b/Library/Homebrew/dev-cmd/tap-readme.rb index e1a3e0eb46..cf5af85ebc 100644 --- a/Library/Homebrew/dev-cmd/tap-readme.rb +++ b/Library/Homebrew/dev-cmd/tap-readme.rb @@ -2,6 +2,8 @@ #: Generate the README.md file for a new tap. module Homebrew + module_function + def tap_readme name = ARGV.first raise "A name is required" if name.nil? diff --git a/Library/Homebrew/dev-cmd/test.rb b/Library/Homebrew/dev-cmd/test.rb index c20edf804b..4898629b01 100644 --- a/Library/Homebrew/dev-cmd/test.rb +++ b/Library/Homebrew/dev-cmd/test.rb @@ -21,6 +21,8 @@ require "sandbox" require "timeout" module Homebrew + module_function + def test raise FormulaUnspecifiedError if ARGV.named.empty? diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index 9b15f9f3ef..1b6af2850c 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -5,6 +5,8 @@ require "fileutils" require "tap" module Homebrew + module_function + def tests (HOMEBREW_LIBRARY/"Homebrew").cd do ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1" diff --git a/Library/Homebrew/dev-cmd/update-test.rb b/Library/Homebrew/dev-cmd/update-test.rb index 8d0391f664..7f20104d81 100644 --- a/Library/Homebrew/dev-cmd/update-test.rb +++ b/Library/Homebrew/dev-cmd/update-test.rb @@ -15,6 +15,8 @@ #: the new repository clone. module Homebrew + module_function + def update_test ENV["HOMEBREW_UPDATE_TO_TAG"] = "1" if ARGV.include?("--to-tag") diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 0cd0d57e67..bf700b0953 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -39,14 +39,21 @@ HOMEBREW_CURL_ARGS = [ require "tap_constants" module Homebrew - include FileUtils - extend self + extend FileUtils - attr_accessor :failed - alias failed? failed + class << self + attr_writer :failed - attr_accessor :raise_deprecation_exceptions - alias raise_deprecation_exceptions? raise_deprecation_exceptions + def failed? + @failed == true + end + + attr_writer :raise_deprecation_exceptions + + def raise_deprecation_exceptions? + @raise_deprecation_exceptions == true + end + end end HOMEBREW_PULL_API_REGEX = %r{https://api\.github\.com/repos/([\w-]+)/([\w-]+)?/pulls/(\d+)} diff --git a/Library/Homebrew/options.rb b/Library/Homebrew/options.rb index 08f459b24f..9f12535317 100644 --- a/Library/Homebrew/options.rb +++ b/Library/Homebrew/options.rb @@ -114,6 +114,8 @@ class Options end module Homebrew + module_function + def dump_options_for_formula(f) f.options.sort_by(&:flag).each do |opt| puts "#{opt.flag}\n\t#{opt.description}" diff --git a/Library/Homebrew/test/test_utils.rb b/Library/Homebrew/test/test_utils.rb index c88c0f4169..422cd6229f 100644 --- a/Library/Homebrew/test/test_utils.rb +++ b/Library/Homebrew/test/test_utils.rb @@ -46,7 +46,7 @@ class UtilTests < Homebrew::TestCase def test_ofail shutup { ofail "foo" } - assert Homebrew.failed + assert Homebrew.failed? ensure Homebrew.failed = false end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 58083fe1be..634da73943 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -224,7 +224,9 @@ def interactive_shell(f = nil) end module Homebrew - def self._system(cmd, *args) + module_function + + def _system(cmd, *args) pid = fork do yield if block_given? args.collect!(&:to_s) @@ -239,12 +241,12 @@ module Homebrew $?.success? end - def self.system(cmd, *args) + def system(cmd, *args) puts "#{cmd} #{args*" "}" if ARGV.verbose? _system(cmd, *args) end - def self.core_tap_version_string + def core_tap_version_string require "tap" tap = CoreTap.instance return "N/A" unless tap.installed? @@ -256,7 +258,7 @@ module Homebrew end end - def self.install_gem_setup_path!(name, version = nil, executable = name) + def install_gem_setup_path!(name, version = nil, executable = name) # Respect user's preferences for where gems should be installed. ENV["GEM_HOME"] = ENV["GEM_OLD_HOME"].to_s ENV["GEM_HOME"] = Gem.user_dir if ENV["GEM_HOME"].empty? @@ -300,11 +302,11 @@ module Homebrew end # Hash of Module => Set(method_names) - @@injected_dump_stat_modules = {} + @injected_dump_stat_modules = {} def inject_dump_stats!(the_module, pattern) - @@injected_dump_stat_modules[the_module] ||= [] - injected_methods = @@injected_dump_stat_modules[the_module] + @injected_dump_stat_modules[the_module] ||= [] + injected_methods = @injected_dump_stat_modules[the_module] the_module.module_eval do instance_methods.grep(pattern).each do |name| next if injected_methods.include? name From acaee035dfddd1fd90b883f19cb2c9f52852c2f3 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 26 Sep 2016 18:00:45 +0200 Subject: [PATCH 2/4] Add compatibility layer for `module Homebrew`. --- Library/Homebrew/compat.rb | 1 + Library/Homebrew/compat/global.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 Library/Homebrew/compat/global.rb diff --git a/Library/Homebrew/compat.rb b/Library/Homebrew/compat.rb index eabc7dfa0e..57c018c048 100644 --- a/Library/Homebrew/compat.rb +++ b/Library/Homebrew/compat.rb @@ -2,6 +2,7 @@ require "compat/fails_with_llvm" require "compat/tap" require "compat/formula" require "compat/formula_specialties" +require "compat/global" require "compat/hardware" require "compat/macos" require "compat/md5" diff --git a/Library/Homebrew/compat/global.rb b/Library/Homebrew/compat/global.rb new file mode 100644 index 0000000000..797e9ffe51 --- /dev/null +++ b/Library/Homebrew/compat/global.rb @@ -0,0 +1,16 @@ +module Homebrew + module_function + + def method_missing(method, *args, &block) + if instance_methods.include?(method) + # odeprecated "#{self}##{method}", "'module_function' or 'def self.#{method}' to convert it to a class method" + return instance_method(method).bind(self).call(*args, &block) + end + super + end + + def respond_to_missing?(method, include_private = false) + return true if method_defined?(method) + super(method, include_private) + end +end From c36f42ce953b4610b2ba62a2b860720ae6d59e01 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 1 Oct 2016 20:33:08 +0200 Subject: [PATCH 3/4] Remove `private_class_method` from commands. --- Library/Homebrew/cmd/commands.rb | 1 - Library/Homebrew/cmd/fetch.rb | 2 -- Library/Homebrew/cmd/help.rb | 1 - Library/Homebrew/cmd/link.rb | 1 - Library/Homebrew/cmd/linkapps.rb | 1 - Library/Homebrew/cmd/list.rb | 2 -- Library/Homebrew/cmd/log.rb | 1 - Library/Homebrew/cmd/tap-info.rb | 2 -- Library/Homebrew/cmd/unlinkapps.rb | 3 --- Library/Homebrew/cmd/update-report.rb | 5 ----- Library/Homebrew/dev-cmd/man.rb | 6 ------ Library/Homebrew/dev-cmd/pull.rb | 8 -------- 12 files changed, 33 deletions(-) diff --git a/Library/Homebrew/cmd/commands.rb b/Library/Homebrew/cmd/commands.rb index 34f0b14e9d..f6445d560c 100644 --- a/Library/Homebrew/cmd/commands.rb +++ b/Library/Homebrew/cmd/commands.rb @@ -55,5 +55,4 @@ module Homebrew cmds << f.basename.to_s.sub(/\.(?:rb|sh)$/, "") if f.file? end end - private_class_method :find_internal_commands end diff --git a/Library/Homebrew/cmd/fetch.rb b/Library/Homebrew/cmd/fetch.rb index f42f140a50..f92ef03b23 100644 --- a/Library/Homebrew/cmd/fetch.rb +++ b/Library/Homebrew/cmd/fetch.rb @@ -106,7 +106,6 @@ module Homebrew false end end - private_class_method :retry_fetch? def fetch_fetchable(f) f.clear_cache if ARGV.force? @@ -127,5 +126,4 @@ module Homebrew f.verify_download_integrity(download) end - private_class_method :fetch_fetchable end diff --git a/Library/Homebrew/cmd/help.rb b/Library/Homebrew/cmd/help.rb index c533885add..793c765ca3 100644 --- a/Library/Homebrew/cmd/help.rb +++ b/Library/Homebrew/cmd/help.rb @@ -86,5 +86,4 @@ module Homebrew end.join.strip end end - private_class_method :command_help end diff --git a/Library/Homebrew/cmd/link.rb b/Library/Homebrew/cmd/link.rb index a8612865b4..98cf98bf77 100644 --- a/Library/Homebrew/cmd/link.rb +++ b/Library/Homebrew/cmd/link.rb @@ -78,5 +78,4 @@ module Homebrew rescue FormulaUnavailableError, TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError false end - private_class_method :keg_only? end diff --git a/Library/Homebrew/cmd/linkapps.rb b/Library/Homebrew/cmd/linkapps.rb index 4f46362cce..bd88409aaa 100644 --- a/Library/Homebrew/cmd/linkapps.rb +++ b/Library/Homebrew/cmd/linkapps.rb @@ -61,5 +61,4 @@ module Homebrew local = opts.fetch(:local, false) Pathname.new(local ? "~/Applications" : "/Applications").expand_path end - private_class_method :linkapps_target end diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index b6bee87fb7..ac13d9c862 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -101,7 +101,6 @@ module Homebrew cd HOMEBREW_PREFIX exec "find", *args end - private_class_method :list_unbrewed def filtered_list names = if ARGV.named.empty? @@ -128,7 +127,6 @@ module Homebrew end end end - private_class_method :filtered_list end class PrettyListing diff --git a/Library/Homebrew/cmd/log.rb b/Library/Homebrew/cmd/log.rb index 734460e887..81f972b028 100644 --- a/Library/Homebrew/cmd/log.rb +++ b/Library/Homebrew/cmd/log.rb @@ -29,5 +29,4 @@ module Homebrew args += ["--", path] unless path.nil? exec "git", "log", *args end - private_class_method :git_log end diff --git a/Library/Homebrew/cmd/tap-info.rb b/Library/Homebrew/cmd/tap-info.rb index 71a98813d5..f31bf480c8 100644 --- a/Library/Homebrew/cmd/tap-info.rb +++ b/Library/Homebrew/cmd/tap-info.rb @@ -80,10 +80,8 @@ module Homebrew end end end - private_class_method :print_tap_info def print_tap_json(taps) puts Utils::JSON.dump(taps.map(&:to_hash)) end - private_class_method :print_tap_json end diff --git a/Library/Homebrew/cmd/unlinkapps.rb b/Library/Homebrew/cmd/unlinkapps.rb index 0df6de929f..d04ef9ee40 100644 --- a/Library/Homebrew/cmd/unlinkapps.rb +++ b/Library/Homebrew/cmd/unlinkapps.rb @@ -25,7 +25,6 @@ module Homebrew unlinkapps_from_dir(linkapps_target(local: false), opts) unlinkapps_from_dir(linkapps_target(local: true), opts) end - private_class_method :unlinkapps_prune def unlinkapps_from_dir(target_dir, opts = {}) return unless target_dir.directory? @@ -58,7 +57,6 @@ module Homebrew puts "Unlinked #{n} app#{plural(n)} from #{target_dir}" end end - private_class_method :unlinkapps_from_dir UNLINKAPPS_PREFIXES = %W[ #{HOMEBREW_CELLAR}/ @@ -78,5 +76,4 @@ module Homebrew ARGV.kegs.any? { |keg| app.start_with?("#{keg}/", "#{keg.opt_record}/") } end end - private_class_method :unlinkapps_unlink? end diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 84faf62896..a7077d8dbf 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -111,7 +111,6 @@ module Homebrew def shorten_revision(revision) Utils.popen_read("git", "-C", HOMEBREW_REPOSITORY, "rev-parse", "--short", revision).chomp end - private_class_method :shorten_revision def install_core_tap_if_necessary core_tap = CoreTap.instance @@ -121,7 +120,6 @@ module Homebrew ENV["HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_CORE"] = revision ENV["HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_CORE"] = revision end - private_class_method :install_core_tap_if_necessary def migrate_legacy_cache_if_necessary legacy_cache = Pathname.new "/Library/Caches/Homebrew" @@ -176,7 +174,6 @@ module Homebrew end end end - private_class_method :migrate_legacy_cache_if_necessary def migrate_legacy_repository_if_necessary return unless HOMEBREW_PREFIX.to_s == "/usr/local" @@ -295,7 +292,6 @@ module Homebrew EOS $stderr.puts e.backtrace end - private_class_method :migrate_legacy_repository_if_necessary def link_completions_and_docs(repository = HOMEBREW_REPOSITORY) command = "brew update" @@ -313,7 +309,6 @@ module Homebrew #{e} EOS end - private_class_method :link_completions_and_docs end class Reporter diff --git a/Library/Homebrew/dev-cmd/man.rb b/Library/Homebrew/dev-cmd/man.rb index 8e645d4014..3395fa673d 100644 --- a/Library/Homebrew/dev-cmd/man.rb +++ b/Library/Homebrew/dev-cmd/man.rb @@ -44,7 +44,6 @@ module Homebrew cask_markup = (HOMEBREW_LIBRARY/"Homebrew/manpages/brew-cask.1.md").read convert_man_page(cask_markup, TARGET_MAN_PATH/"brew-cask.1") end - private_class_method :regenerate_man_pages def path_glob_commands(glob) Pathname.glob(glob) @@ -57,7 +56,6 @@ module Homebrew end .reject { |s| s.strip.empty? || s.include?("@hide_from_man_page") } end - private_class_method :path_glob_commands def build_man_page template = (SOURCE_PATH/"brew.1.md.erb").read @@ -75,13 +73,11 @@ module Homebrew ERB.new(template, nil, ">").result(variables.instance_eval { binding }) end - private_class_method :build_man_page def sort_key_for_path(path) # Options after regular commands (`~` comes after `z` in ASCII table). path.basename.to_s.sub(/\.(rb|sh)$/, "").sub(/^--/, "~~") end - private_class_method :sort_key_for_path def convert_man_page(markup, target) manual = target.basename(".1") @@ -114,7 +110,6 @@ module Homebrew target.atomic_write ronn.read end end - private_class_method :convert_man_page def target_path_to_format(target) case target.basename @@ -124,5 +119,4 @@ module Homebrew odie "Failed to infer output format from '#{target.basename}'." end end - private_class_method :target_path_to_format end diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index d64ebd4d17..7e6e86a850 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -257,12 +257,10 @@ module Homebrew end published end - private_class_method :publish_changed_formula_bottles def pull_patch(url, description = nil) PatchPuller.new(url, description).pull_patch end - private_class_method :pull_patch class PatchPuller attr_reader :base_url @@ -342,7 +340,6 @@ module Homebrew end { files: files, formulae: formulae, others: others } end - private_class_method :files_changed_in_patch # Get current formula versions without loading formula definition in this process # Returns info as a hash (type => version), for pull.rb's internal use @@ -359,7 +356,6 @@ module Homebrew end versions end - private_class_method :current_versions_from_info_external def subject_for_bump(formula, old, new) if old[:nonexistent] @@ -399,12 +395,10 @@ module Homebrew end subject end - private_class_method :subject_for_bump def pbcopy(text) Utils.popen_write("pbcopy") { |io| io.write text } end - private_class_method :pbcopy # Publishes the current bottle files for a given formula to Bintray def publish_bottle_file_on_bintray(f, creds) @@ -421,7 +415,6 @@ module Homebrew "-d", '{"publish_wait_for_secs": 0}', "https://api.bintray.com/content/homebrew/#{repo}/#{package}/#{version}/publish" end - private_class_method :publish_bottle_file_on_bintray # Formula info drawn from an external "brew info --json" call class FormulaInfoFromJson @@ -582,5 +575,4 @@ module Homebrew end end end - private_class_method :verify_bintray_published end From 9690c94f9dcc78d2a00093e21be412c70776541c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 27 Sep 2016 16:38:05 +0200 Subject: [PATCH 4/4] Fix Style/GuardClause style offense. --- Library/Homebrew/utils.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 634da73943..7c68437cad 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -293,12 +293,11 @@ module Homebrew odie "Failed to install/update the '#{name}' gem." if exit_code.nonzero? end - unless which executable - odie <<-EOS.undent - The '#{name}' gem is installed but couldn't find '#{executable}' in the PATH: - #{ENV["PATH"]} - EOS - end + return if which(executable) + odie <<-EOS.undent + The '#{name}' gem is installed but couldn't find '#{executable}' in the PATH: + #{ENV["PATH"]} + EOS end # Hash of Module => Set(method_names)