Class: Rabbit::GemPusher

Inherits:
Object
  • Object
show all
Includes:
GetText, Rake::DSL
Defined in:
lib/rabbit/gem-pusher.rb

Constant Summary

Constants included from GetText

Rabbit::GetText::DOMAIN

Instance Method Summary collapse

Methods included from GetText

included

Constructor Details

#initialize(gem_path, user) ⇒ GemPusher

Returns a new instance of GemPusher.


29
30
31
32
# File 'lib/rabbit/gem-pusher.rb', line 29

def initialize(gem_path, user)
  @gem_path = gem_path
  @user = user
end

Instance Method Details

#pushObject


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rabbit/gem-pusher.rb', line 34

def push
  credentials_path = File.expand_path("~/.gem/credentials")
  credentials_path_exist = File.exist?(credentials_path)
  if credentials_path_exist
    credentials = YAMLLoader.load(File.read(credentials_path))
  else
    credentials = {}
  end
  unless credentials.key?(@user.to_sym)
    credentials[@user.to_sym] = retrieve_api_key
    File.open(credentials_path, "w") do |credentials_file|
      credentials_file.print(credentials.to_yaml)
    end
    unless credentials_path_exist
      File.chmod(0600, credentials_path)
    end
  end
  ruby("-S", "gem", "push", @gem_path,
       "--key", @user)
end