lib/buildar.rb in buildar-2.0.2.2 vs lib/buildar.rb in buildar-3.0.0.1
- old
+ new
@@ -12,11 +12,11 @@
# only works for versions consisting of integers delimited by periods (dots)
#
def self.bump(position, version)
pos = [:major, :minor, :patch, :build].index(position) || position
places = version.split('.')
- if pos >= places.length and pos <= places.length + 2
+ if places.length <= pos and pos <= places.length + 3
# add zeroes to places up to pos
# allows bump(:build, '0') #=> '0.0.0.1'
places.length.upto(pos) { |i| places[i] = 0 }
end
raise "bad position: #{pos} (for version #{version})" unless places[pos]
@@ -83,13 +83,13 @@
#
# tasks to be kept out of @ns namespace
#
desc "config check"
- task :buildar do
+ task buildar: :valid_gemspec do
spacer = " " * 14
- gemspec = self.gemspec || raise("no valid gemspec")
+ gemspec = self.gemspec
puts
puts " Project: #{gemspec.name} #{gemspec.version}"
puts "Gemspec file: #{@gemspec_file}" if @gemspec_file
puts <<EOF
Version file: #{@version_file}
@@ -126,20 +126,20 @@
end
end
def define_tasks
desc "invoke :test and :bump_build conditionally"
- task :pre_build => @pkg_dir do
+ task pre_build: @pkg_dir do
Rake::Task[:test].invoke if Rake::Task.task_defined? :test
Rake::Task['bump:build'].invoke if @version_file
end
# can't make this a file task, because the version could be bumped
# as a dependency, changing the target file
#
desc "build a .gem in #{@pkg_dir}/ using `gem build`"
- task :build => :pre_build do
+ task build: :pre_build do
if @gemspec_file
sh "gem build #{@gemspec_file}"
mv File.basename(self.gem_file), self.gem_file
else
Rake::Task[:gem_package].invoke
@@ -148,11 +148,11 @@
# roughly equivalent to `gem build self.gemspec`
# operates with a hard or soft gemspec
#
desc "build a .gem in #{@pkg_dir}/ using Gem::PackageTask"
- task :gem_package => :pre_build do
+ task gem_package: :pre_build do
# definine the task at runtime, rather than requiretime
# so that the gemspec will reflect any version bumping since requiretime
require 'rubygems/package_task'
Gem::PackageTask.new(self.gemspec).define
Rake::Task["package"].invoke
@@ -162,32 +162,40 @@
task :built do
Rake::Task[:build].invoke unless File.exists? self.gem_file
end
desc "publish the current version to rubygems.org"
- task :publish => :built do
+ task publish: :built do
sh "gem push #{self.gem_file}"
end
desc "build, publish" << (@use_git ? ", tag " : '')
- task :release => [:build, :publish] do
+ task release: [:build, :publish] do
Rake::Task[:tag].invoke if @use_git
end
desc "install the current version"
- task :install => :built do
+ task install: :built do
sh "gem install #{self.gem_file}"
end
desc "build a new version and install"
- task :install_new => [:build, :install]
+ task install_new: [:build, :install]
desc "display current version"
- task :version do
+ task version: :valid_gemspec do
puts self.gemspec.version
end
+ task :valid_gemspec do
+ unless self.gemspec
+ msg = "gemspec required"
+ msg += "; checked #{self.gemspec_file}" if self.gemspec_file
+ raise msg
+ end
+ end
+
#
# Optional tasks
#
if @version_file
@@ -199,10 +207,10 @@
end
end
if @use_git
desc "annotated git tag with version and message"
- task :tag => :message do
+ task tag: :message do
Rake::Task[:test].invoke if Rake::Task.task_defined? :test
tagname = "v#{self.gemspec.version}"
message = ENV['message'] || "auto-tagged #{tagname} by Buildar"
sh "git tag -a #{tagname.inspect} -m #{message.inspect}"
sh "git push origin --tags"