Skip to content

Commit

Permalink
Don't load gemspec on init
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Mar 22, 2017
1 parent cd764ac commit 69fa54c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/apress/gems/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class Cli

def initialize(options)
@options = DEFAULT_OPTIONS.merge(options)

load_gemspec
end

def changelog
Expand All @@ -48,15 +46,15 @@ def bump
def build
FileUtils.mkdir_p('pkg')

spawn "gem build -V #{@spec_path}"
built_gem_path = Dir["#{@gemspec.name}-*.gem"].sort_by { |f| File.mtime(f) }.last
spawn "gem build -V #{spec_path}"
built_gem_path = Dir["#{gemspec.name}-*.gem"].sort_by { |f| File.mtime(f) }.last

FileUtils.mv(built_gem_path, 'pkg')
log 'Package built'
end

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

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

def exist?
cmd = "gem search #{@gemspec.name} --clear-sources -s '#{source_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 Down Expand Up @@ -180,12 +178,23 @@ def spawn(cmd)
end

def load_gemspec
return if defined?(@gemspec)
gemspecs = Dir[File.join(Dir.pwd, '{,*}.gemspec')]
raise 'Unable to determine name from existing gemspec' unless gemspecs.size == 1
@spec_path = gemspecs.first
@gemspec = Bundler.load_gemspec(@spec_path)
end

def gemspec
load_gemspec
@gemspec
end

def spec_path
load_gemspec
@spec_path
end

def upload_gem(repo_uri, tarball_name)
repo_uri.path = '/upload'

Expand Down

0 comments on commit 69fa54c

Please sign in to comment.