Sha256: 058c9a16ce0a5f1e6f47bb32507b71e0c189acb1f958d50f36ea7911670f9860

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

require 'rubygems/commands/build_command'
require 'rubygems/commands/push_command'
require 'rubygems/commands/tag_command'

class Gem::Commands::ReleaseCommand < Gem::Command
  include GemRelease, Gem::Commands
  include Helpers, CommandOptions

  DEFAULTS = {
    :tag   => false,
    :quiet => false,
    :key   => '',
    :host  => ''
  }

  attr_reader :arguments, :usage

  def initialize(options = {})
    super 'release', 'Build gem from a gemspec and push to rubygems.org', DEFAULTS.merge(options)

    option :tag,   '-t', 'Create a git tag and push --tags to origin'
    option :quiet, '-q', 'Do not output status messages'
    option :key,   '-k', 'Use the given API key from ~/.gem/credentials'
    option :host,  '-h', 'Push to a gemcutter-compatible host other than rubygems.org'

    @arguments = "gemspec - optional gemspec file name, will use the first *.gemspec if not specified"
    @usage = "#{program_name} [gemspec]"
  end

  def execute
    in_gemspec_dirs do
      build
      push
      remove
    end

    tag if options[:tag]
    say "All is good, thanks my friend.\n"
  end

  protected

    def build
      BuildCommand.new.invoke(gemspec_filename)
    end

    def push
      args = []
      [:key, :host].each do |option|
        args += ["--#{option}", options[option]] unless options[option] == ''
      end
      args += "--quiet" if quiet?

      PushCommand.new.invoke(gem_filename, *args)
    end

    def remove
      say "Deleting left over gem file #{gem_filename}" unless quiet?
      `rm #{gem_filename}`
    end

    def tag
      TagCommand.new.invoke
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gem-release-0.2.2 lib/rubygems/commands/release_command.rb
gem-release-0.2.1 lib/rubygems/commands/release_command.rb
gem-release-0.2.0 lib/rubygems/commands/release_command.rb