Permalink
Browse files

clean-up versioning, rakefile.

  • Loading branch information...
joshbuddy committed Jul 19, 2010
1 parent 2b7739a commit bde2ea3714788780df259d24b78f66aa02acce1d
Showing with 134 additions and 12 deletions.
  1. +2 −8 Rakefile
  2. +126 −0 ext/gem_rake.rb
  3. +4 −3 http_router.gemspec
  4. +2 −1 lib/http_router/version.rb
View
@@ -7,10 +7,6 @@ Spec::Rake::SpecTask.new(:spec) do |t|
t.spec_files = FileList['spec/**/*_spec.rb']
end
task 'tumbler:preflight' do
Rake::Task["spec"].invoke
end
begin
require 'code_stats'
CodeStats::Tasks.new
@@ -25,8 +21,6 @@ Rake::RDocTask.new do |rd|
rd.rdoc_dir = 'rdoc'
end
require 'ext/gem_rake'
# automatically added Tumbler tasks
require 'tumbler'
Tumbler.use_rake_tasks
Bundler::GemHelper.install_tasks
View
@@ -0,0 +1,126 @@
module Bundler
class GemHelper
def self.install_tasks
dir = caller.find{|c| /Rakefile:/}[/^(.*?)\/Rakefile:/, 1]
GemHelper.new(dir).install
end
attr_reader :spec_path, :base, :name
def initialize(base, name = nil)
@base = base
@name = name || interpolate_name
@spec_path = File.join(@base, "#{@name}.gemspec")
end
def install
desc 'Build your gem into the pkg directory'
task 'build' do
build_gem
end
desc 'Install your gem into the pkg directory'
task 'install' do
install_gem
end
desc 'Push your gem to rubygems'
task 'push' do
push_gem
end
end
def build_gem
file_name = nil
sh("gem build #{spec_path}") {
file_name = File.basename(built_gem_path)
FileUtils.mkdir_p(File.join(base, 'pkg'))
FileUtils.mv(built_gem_path, 'pkg')
}
File.join(base, 'pkg', file_name)
end
def install_gem
built_gem_path = build_gem
sh("gem install #{built_gem_path}")
end
def push_gem
guard_clean
guard_already_tagged
tag_version {
git_push
rubygem_push(build_gem)
}
end
protected
def rubygem_push(path)
sh("gem push #{path}")
end
def built_gem_path
Dir[File.join(base, "#{name}-*.gem")].sort_by{|f| File.mtime(f)}.last
end
def interpolate_name
gemspecs = Dir[File.join(base, "*.gemspec")]
raise "Unable to determine name from existing gemspec." unless gemspecs.size == 1
File.basename(gemspecs.first)[/^(.*)\.gemspec$/, 1]
end
def git_push
sh "git push --all"
sh "git push --tags"
end
def guard_already_tagged
sh('git tag').split(/\n/).include?(current_version_tag) and raise("This tag has already been committed to the repo.")
end
def guard_clean
clean? or raise("There are files that need to be committed first.")
end
def clean?
sh("git ls-files -dm").split("\n").size.zero?
end
def tag_version
sh "git tag #{current_version_tag}"
yield if block_given?
rescue
sh "git tag -d #{current_version_tag}"
raise
end
def current_version
raise("Version file could not be found at #{version_file_path}") unless File.exist?(version_file_path)
File.read(version_file_path)[/V(ERSION|ersion)\s*=\s*(["'])(.*?)\2/, 3]
end
def version_file_path
File.join(base, 'lib', name, 'version.rb')
end
def current_version_tag
"v#{current_version}"
end
def sh(cmd, &block)
output, code = sh_with_code(cmd, &block)
code == 0 ? output : raise(output)
end
def sh_with_code(cmd, &block)
output = ''
Dir.chdir(base) {
output = `#{cmd}`
block.call if block and $? == 0
}
[output, $?]
end
end
end
View
@@ -7,17 +7,18 @@ Gem::Specification.new do |s|
s.version = HttpRouter::VERSION
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Joshua Hull"]
s.date = '2010-07-12'
s.description = %q{A kick-ass HTTP router for use in Rack & Sinatra}
s.date = HttpRouter::RELEASE_DATE
s.summary = "A kick-ass HTTP router for use in Rack & Sinatra"
s.description = "This library allows you to recognize and build URLs in a Rack application. As well it contains an interface for use within Sinatra."
s.email = %q{joshbuddy@gmail.com}
s.extra_rdoc_files = ['README.rdoc']
s.files = `git ls-files`.split("\n")
s.homepage = %q{http://github.com/joshbuddy/http_router}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
s.summary = %q{A kick-ass HTTP router for use in Rack & Sinatra}
s.test_files = `git ls-files`.split("\n").select{|f| f =~ /^spec/}
s.rubyforge_project = 'http_router'
# dependencies
s.add_runtime_dependency 'rack', '>=1.0'
@@ -1,4 +1,5 @@
# encoding: utf-8
class HttpRouter #:nodoc
VERSION = '0.3.4'
VERSION = '0.3.4'.freeze
RELEASE_DATE = '2010-07-12'.freeze
end

0 comments on commit bde2ea3

Please sign in to comment.