Merge pull request #8492 from reitermarkus/document-shebang

Document `Shebang`.
This commit is contained in:
Markus Reiter 2020-08-26 11:22:09 +02:00 committed by GitHub
commit 6fe8b66a8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -22,7 +22,6 @@ Style/Documentation:
- 'utils/gems.rb'
- 'utils/notability.rb'
- 'utils/popen.rb'
- 'utils/shebang.rb'
- 'utils/shell.rb'
- 'utils/livecheck_formula.rb'
- 'version.rb'

View File

@ -1,9 +1,15 @@
# frozen_string_literal: true
module Utils
# Helper functions for manipulating shebang lines.
#
# @api private
module Shebang
module_function
# Specification on how to rewrite a given shebang.
#
# @api private
class RewriteInfo
attr_reader :regex, :max_length, :replacement
@ -14,6 +20,12 @@ module Utils
end
end
# Rewrite shebang for the given `paths` using the given `rewrite_info`.
#
# @example
# rewrite_shebang detected_python_shebang, bin/"script.py"
#
# @api public
def rewrite_shebang(rewrite_info, *paths)
paths.each do |f|
f = Pathname(f)