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

archive_format[RW]

@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

package_dir[RW]

@return [String] the default relative directory where {SGem} will place

generated gems and archives unless otherwise specified

@see SGem#package_dir

Public Class Methods

new(spec) click to toggle source

@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

archive_format() click to toggle source

@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
name() click to toggle source

@return [String] the name of the gem for this instance of {SGem}

# File lib/sgem.rb, line 34
def name
  @name ||= @spec.name
end
package_dir() click to toggle source

@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
version() click to toggle source

@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

define_tasks() click to toggle source

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
package(ext) click to toggle source

@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