class SGem
{SGem} is a simple, minimalistic way to build and publish gems using `rake`.
{SGem} is based on the excellent [mg](github.com/sr/mg) (written by [Ryan Tomayko](tomayko.com), extracted by [Simon Rozet](atonie.org)).
Constants
- VERSION
The semantic version of
SGem
.
Attributes
@note This format must be supported by `git-archive`. @return [String] the default archive format for {SGem} to use unless
otherwise specified
@see SGem#archive_format
@return [String] the default relative directory where {SGem} will place
generated gems and archives unless otherwise specified
@see SGem#package_dir
Public Class Methods
@param spec [String] the gemspec for this instance of {SGem}
# File lib/sgem.rb, line 28 def initialize(spec) @spec = Gem::Specification.load(spec) define_tasks end
Public Instance Methods
@note This format must be supported by `git-archive`. @return [String] the archive format for {SGem} to use
# File lib/sgem.rb, line 54 def archive_format @format ||= ENV['ARCHIVE'] || self.class.archive_format || '.tar.gz' end
@return [String] the name of the gem for this instance of {SGem}
# File lib/sgem.rb, line 34 def name @name ||= @spec.name end
@return [String] the relative directory where {SGem} will place generated
gems and archives
# File lib/sgem.rb, line 46 def package_dir return @dir if @dir dir = ENV['DEST'] || self.class.package_dir || 'pkg/' @dir = dir.end_with?('/') ? dir : "#{dir}/" end
@return [Gem::Version] the version of the gemspec for this instance of
{SGem}
# File lib/sgem.rb, line 40 def version @version ||= @spec.version end
Private Instance Methods
Defines the {SGem} `rake` tasks. @return [void]
# File lib/sgem.rb, line 66 def define_tasks directory package_dir CLOBBER.include(package_dir) desc 'build and install as local gem' task 'gem:install' => package('.gem') do sh "gem install #{package(".gem")}" end desc "build gem into #{package_dir}" task :gem => package('.gem') desc "build archive into #{package_dir}" task :archive => package(archive_format) desc "build gem and archive into #{package_dir}" task :package => ['.gem', archive_format].map { |ext| package(ext) } file package(archive_format) => package_dir do |f| sh "git archive --prefix=#{name}-#{version}/ -o #{f.name} HEAD" end file package('.gem') => package_dir do |f| sh "gem build #{name}.gemspec" mv File.basename(f.name), f.name end desc 'push the gem to rubygems.org' task 'gem:publish' => package('.gem') do %i(test spec).each { |t| t.invoke if Rake::Task.task_defined?(t) } sh "gem push #{package('.gem')}" end end
@param ext [String] the extension to apply @return [String] the package name with the given extension
# File lib/sgem.rb, line 60 def package(ext) "#{package_dir}#{name}-#{version}#{ext}" end