class GemHadar

def gem_push_task

accordingly.
declines to push, appropriate messages are displayed and the task exits
API key from the environment. If the gem file does not exist or the user
confirmation before pushing, and uses the gem push command with an optional
Otherwise, it verifies the existence of the gem file, prompts the user for
project is in developing mode and skips the push operation if so.
the process of uploading the gem package to RubyGems. It checks if the
This method sets up a :gem:push task under the Rake namespace that handles

file to RubyGems.
The gem_push_task method defines a Rake task for pushing the generated gem
def gem_push_task
  namespace :gem do
    path = "pkg/#{name_version}.gem"
    desc "Push gem file #{File.basename(path)} to rubygems"
    if developing
      task :push => :build do
        puts "Skipping push to rubygems while developing mode is enabled."
      end
    else
      task :push => :build do
        if File.exist?(path)
          if ask?("Do you really want to push #{path.inspect} to rubygems? "\
              "(yes/NO) ", /\Ayes\z/i)
            then
            key = ENV['GEM_HOST_API_KEY'].full? { |k| "--key #{k} " }
            sh "gem push #{key}#{path}"
          else
            exit 1
          end
        else
          warn "Cannot push gem to rubygems: #{path.inspect} doesn't exist."
          exit 1
        end
      end
    end
  end
end