Skip to content

Instantly share code, notes, and snippets.

@rkh
Created June 4, 2011 14:54
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rkh/1007951 to your computer and use it in GitHub Desktop.
Save rkh/1007951 to your computer and use it in GitHub Desktop.
Gem::Specification.new do |s|
# totally generic
version_file = Dir['lib/*/{*/,}version.rb'].first
s.name = version_file.split('/')[1..-2].join('-')
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.authors = `git shortlog -sn`.scan(/[^\d\s].*/)
s.email = `git shortlog -sne`.scan(/[^<]+@[^>]+/)
s.require_paths = ["lib"]
# generic, but you might want to change it
github_user = `git config github.user`.strip
s.homepage = "http://github.com/#{github_user}/#{s.name}"
fail "`git config github.users` not set" if github_user.empty?
# let's figure out the version
wrapper = Module.new
wrapper.module_eval File.read(version_file)
wrapper.constants.map { |n| wrapper.const_get(n) }.each do |c|
if c.const_defined? :VERSION
s.version = c::VERSION
elsif nested = c.constants.detect { |n| c.const_get(n).const_defined? :VERSION }
s.version = nested::VERSION
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment