Skip to content

Commit

Permalink
Add option for define url of gem source
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Mar 22, 2017
1 parent f4c592b commit abdfc8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions bin/apress-gem
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ opt_parser = OptionParser.new do |opt|
opt.on('-q', '--quiet', 'silence command progress meter') do
options[:quiet] = true
end

opt.on('-s', '--source URL', 'url of gem source, default https://gems.railsc.ru/') do |value|
options[:source] = value
end
end

opt_parser.parse!
Expand Down
17 changes: 10 additions & 7 deletions lib/apress/gems/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Cli
push: true,
remote: "origin",
branch: "master",
quiet: false
quiet: false,
source: 'https://gems.railsc.ru/'
}.freeze

def initialize(options)
Expand Down Expand Up @@ -56,7 +57,7 @@ def build

def upload
tarball_name = "#{@gemspec.name}-#{version_or_current}.gem"
upload_gem(upload_uri, tarball_name)
upload_gem(source_uri, tarball_name)
end

def tag
Expand Down Expand Up @@ -116,7 +117,7 @@ def find_version
end

def exist?
cmd = "gem search #{@gemspec.name} --clear-sources -s '#{upload_uri}' --exact --quiet -a"
cmd = "gem search #{@gemspec.name} --clear-sources -s '#{source_uri}' --exact --quiet -a"
output = spawn(cmd)
escaped_version = Regexp.escape(version_or_current)
!!(output =~ /[( ]#{escaped_version}[,)]/)
Expand All @@ -132,10 +133,12 @@ def update_version
end
end

def upload_uri
uri = URI.parse(GEMS_URL)
uri.userinfo = Bundler.settings[GEMS_URL]
uri
def source_uri
return @uri if defined?(@uri)
source_url = @options.fetch(:source)
@uri = URI.parse(source_url)
@uri.userinfo = Bundler.settings[source_url]
@uri
end

def pull_latest
Expand Down

0 comments on commit abdfc8d

Please sign in to comment.