Class: Gem::Tasks::Push

Inherits:
Task
  • Object
show all
Defined in:
lib/rubygems/tasks/push.rb

Overview

The push task.

Constant Summary

Constants included from Printing

Gem::Tasks::Printing::ANSI_BRIGHT, Gem::Tasks::Printing::ANSI_CLEAR, Gem::Tasks::Printing::ANSI_GREEN, Gem::Tasks::Printing::ANSI_RED, Gem::Tasks::Printing::ANSI_YELLOW, Gem::Tasks::Printing::DEBUG_PREFIX, Gem::Tasks::Printing::ERROR_PREFIX, Gem::Tasks::Printing::STATUS_PREFIX

Instance Attribute Summary collapse

Attributes inherited from Task

#project

Instance Method Summary collapse

Methods inherited from Task

#bundle, #gem, #gemspec_tasks, #invoke, #namespaced_tasks, #run, #task?

Methods included from Printing

#debug, #error, #status

Constructor Details

#initialize(host: nil, key: nil) {|_self| ... } ⇒ Push

Initializes the push task.

Parameters:

  • host (String, nil) (defaults to: nil)

    The rubygems host to push gems to.

  • key (String, nil) (defaults to: nil)

    An optional rubygems API key.

Yields:

  • (_self)

Yield Parameters:



33
34
35
36
37
38
39
40
41
# File 'lib/rubygems/tasks/push.rb', line 33

def initialize(host: nil, key: nil)
  super()

  @host = host
  @key  = key

  yield self if block_given?
  define
end

Instance Attribute Details

#hostString?

The rubygems host to push gems to.

Returns:

  • (String, nil)


15
16
17
# File 'lib/rubygems/tasks/push.rb', line 15

def host
  @host
end

#keyString?

The rubygems API key.

Returns:

  • (String, nil)

Since:

  • 0.3.0



22
23
24
# File 'lib/rubygems/tasks/push.rb', line 22

def key
  @key
end

Instance Method Details

#defineObject

Defines the push task.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rubygems/tasks/push.rb', line 46

def define
  task :validate

  namespace :push do
    @project.builds.each do |build,packages|
      path = packages[:gem]

      task build => [:validate, path] do
        if @host
          status "Pushing #{File.basename(path)} to #{@host} ..."
        else
          status "Pushing #{File.basename(path)} ..."
        end

        push(path)
      end
    end
  end

  gemspec_tasks :push

  # backwards compatibility for Hoe
  task :publish => :push
end

#push(path) ⇒ Boolean

Pushes the gem by running gem push.

Parameters:

  • path (String)

    The path to the .gem file.

Returns:

  • (Boolean)

    Specifies whether gem push was successful or not.



82
83
84
85
86
87
88
# File 'lib/rubygems/tasks/push.rb', line 82

def push(path)
  arguments = ['gem', 'push', path]
  arguments.push('--key',   @key) if @key
  arguments.push('--host', @host) if @host

  return run(*arguments)
end