Skip to content

Commit

Permalink
Use some time Thor tasks for gem management (on Gemcutter) -- no more…
Browse files Browse the repository at this point in the history
… Jeweler
  • Loading branch information
brynary committed Oct 28, 2009
1 parent 8707f06 commit 8127280
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 23 deletions.
22 changes: 0 additions & 22 deletions Rakefile
@@ -1,28 +1,6 @@
require "rubygems"
require "spec/rake/spectask"

$LOAD_PATH.unshift "lib"
require "rack/bug"

begin
require 'jeweler'

Jeweler::Tasks.new do |s|
s.name = "rack-bug"
s.author = "Bryan Helmkamp"
s.email = "bryan" + "@" + "brynary.com"
s.homepage = "http://github.com/brynary/rack-bug"
s.summary = "Debugging toolbar for Rack applications implemented as middleware"
# s.description = "TODO"
s.rubyforge_project = "rack-bug"
s.extra_rdoc_files = %w(README.rdoc MIT-LICENSE.txt)
end

Jeweler::RubyforgeTasks.new
rescue LoadError
puts "Jeweler not available. Install it with: gem install jeweler"
end

Spec::Rake::SpecTask.new do |t|
t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
end
Expand Down
109 changes: 109 additions & 0 deletions Thorfile
@@ -0,0 +1,109 @@
module GemHelpers

def generate_gemspec
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), "lib")))
require "rack/bug"

Gem::Specification.new do |s|
s.name = "rack-bug"
s.version = Rack::Bug::VERSION
s.author = "Bryan Helmkamp"
s.email = "bryan@brynary.com"
s.homepage = "http://github.com/brynary/rack-bug"
s.summary = "Debugging toolbar for Rack applications implemented as middleware"
# s.description = "TODO"
s.rubyforge_project = "rack-bug"

require "git"
repo = Git.open(".")

s.files = normalize_files(repo.ls_files.keys - repo.lib.ignored_files)
s.test_files = normalize_files(Dir['spec/**/*.rb'] - repo.lib.ignored_files)

s.has_rdoc = true
s.extra_rdoc_files = %w[README.rdoc MIT-LICENSE.txt]

s.add_dependency "rack", ">= 1.0"
end
end

def normalize_files(array)
# only keep files, no directories, and sort
array.select do |path|
File.file?(path)
end.sort
end

# Adds extra space when outputting an array. This helps create better version
# control diffs, because otherwise it is all on the same line.
def prettyify_array(gemspec_ruby, array_name)
gemspec_ruby.gsub(/s\.#{array_name.to_s} = \[.+?\]/) do |match|
leadin, files = match[0..-2].split("[")
leadin + "[\n #{files.split(",").join(",\n ")}\n ]"
end
end

def read_gemspec
@read_gemspec ||= eval(File.read("rack-bug.gemspec"))
end

def sh(command)
puts command
system command
end
end

class Default < Thor
include GemHelpers

desc "gemspec", "Regenerate rack-bug.gemspec"
def gemspec
File.open("rack-bug.gemspec", "w") do |file|
gemspec_ruby = generate_gemspec.to_ruby
gemspec_ruby = prettyify_array(gemspec_ruby, :files)
gemspec_ruby = prettyify_array(gemspec_ruby, :test_files)
gemspec_ruby = prettyify_array(gemspec_ruby, :extra_rdoc_files)

file.write gemspec_ruby
end

puts "Wrote gemspec to rack-bug.gemspec"
read_gemspec.validate
end

desc "build", "Build a rack-bug gem"
def build
sh "gem build rack-bug.gemspec"
FileUtils.mkdir_p "pkg"
FileUtils.mv read_gemspec.file_name, "pkg"
end

desc "install", "Install the latest built gem"
def install
sh "gem install --local pkg/#{read_gemspec.file_name}"
end

desc "release", "Release the current branch to GitHub and Gemcutter"
def release
gemspec
build
Release.new.tag
Release.new.gem
end
end

class Release < Thor
include GemHelpers

desc "tag", "Tag the gem on the origin server"
def tag
release_tag = "v#{read_gemspec.version}"
sh "git tag -a #{release_tag} -m 'Tagging #{release_tag}'"
sh "git push origin #{release_tag}"
end

desc "gem", "Push the gem to Gemcutter"
def gem
sh "gem push pkg/#{read_gemspec.file_name}"
end
end
2 changes: 1 addition & 1 deletion lib/rack/bug.rb
Expand Up @@ -20,7 +20,7 @@ module Rack::Bug
autoload :TemplatesPanel, "rack/bug/panels/templates_panel"
autoload :TimerPanel, "rack/bug/panels/timer_panel"

VERSION = File.read(File.join(File.dirname(__FILE__), "..", "..", "VERSION")).strip
VERSION = "0.2.2"

class SecurityError < StandardError
end
Expand Down

0 comments on commit 8127280

Please sign in to comment.