Skip to content

Commit

Permalink
Move url2name to formula_creator.rb
Browse files Browse the repository at this point in the history
Per review comments
  • Loading branch information
abitrolly committed Nov 23, 2023
1 parent 3873711 commit 999f1a2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
19 changes: 0 additions & 19 deletions Library/Homebrew/dev-cmd/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,6 @@ def create_args
end
end

def url2name(url)
odebug "url: #{url}"
stem = Pathname.new(url).stem
odebug "stem: #{stem}"
# special cases first
name = if stem.start_with? "index.cgi"
# http://www.codesrc.com/gitweb/index.cgi?p=libzipper.git;a=summary
# https://github.com/Homebrew/brew/pull/9459
stem.rpartition("=").last
elsif url =~ %r{github\.com/\S+/(\S+)/(archive|releases)/}
Regexp.last_match(1)
else
pathver = Version.parse(stem).to_s
stem.sub(/[-_.]?#{Regexp.escape(pathver)}$/, "")
end
odebug "url2name: #{name}"
name
end

# Create a formula from a tarball URL.
def create
args = create_args.parse
Expand Down
21 changes: 21 additions & 0 deletions Library/Homebrew/formula_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
require "erb"

module Homebrew
module_function

def url2name(url)
odebug "url: #{url}"
stem = Pathname.new(url).stem
odebug "stem: #{stem}"
# special cases first
name = if stem.start_with? "index.cgi"
# http://www.codesrc.com/gitweb/index.cgi?p=libzipper.git;a=summary
# https://github.com/Homebrew/brew/pull/9459
stem.rpartition("=").last
elsif url =~ %r{github\.com/\S+/(\S+)/(archive|releases)/}
Regexp.last_match(1)
else
pathver = Version.parse(stem).to_s
stem.sub(/[-_.]?#{Regexp.escape(pathver)}$/, "")
end
odebug "url2name: #{name}"
name
end

# Class for generating a formula from a template.
#
# @api private
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/dev-cmd/create_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require "cmd/shared_examples/args_parse"
require "dev-cmd/create"
require "formula_creator"

describe "brew create" do
let(:url) { "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" }
Expand Down

0 comments on commit 999f1a2

Please sign in to comment.