Class: Gem::Commands::InaboxCommand

Inherits:
Gem::Command
  • Object
show all
Defined in:
lib/rubygems/commands/inabox_command.rb

Instance Method Summary collapse

Constructor Details

#initializeInaboxCommand

Returns a new instance of InaboxCommand


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rubygems/commands/inabox_command.rb', line 16

def initialize
  super 'inabox', description

  add_option('-c', '--configure', "Configure GemInABox") do |value, options|
    options[:configure] = true
  end

  add_option('-g', '--host HOST', "Host to upload to.") do |value, options|
    options[:host] = value
  end

  add_option('-o', '--overwrite', "Overwrite Gem.") do |value, options|
    options[:overwrite] = true
  end

  add_option('-p', '--port', "Sets port") do |value, options|
    options[:port] = value
  end
end

Instance Method Details

#argumentsObject


8
9
10
# File 'lib/rubygems/commands/inabox_command.rb', line 8

def arguments
  "GEM       built gem to push up"
end

#config_pathObject


70
71
72
# File 'lib/rubygems/commands/inabox_command.rb', line 70

def config_path
  File.join(Gem.user_home, '.gem', 'geminabox')
end

#configureObject


74
75
76
77
78
# File 'lib/rubygems/commands/inabox_command.rb', line 74

def configure
  say "Enter the root url for your personal geminabox instance (e.g. http://gems/)."
  host = ask("Host:")
  self.geminabox_host = host
end

#descriptionObject


4
5
6
# File 'lib/rubygems/commands/inabox_command.rb', line 4

def description
  'Push a gem up to your GemInABox'
end

#executeObject


41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rubygems/commands/inabox_command.rb', line 41

def execute
  last_minute_requires!
  return configure if options[:configure]
  configure unless geminabox_host

  if options[:args].size == 0
    say "You didn't specify a gem, looking for one in . and in ./pkg/..."
    gemfiles = [GeminaboxClient::GemLocator.find_gem(Dir.pwd)]
  else
    gemfiles = get_all_gem_names
  end

  send_gems(gemfiles)
end

#geminabox_hostObject


80
81
82
# File 'lib/rubygems/commands/inabox_command.rb', line 80

def geminabox_host
  @geminabox_host ||= options[:host] || Gem.configuration.load_file(config_path)[:host]
end

#geminabox_host=(host) ⇒ Object


84
85
86
87
88
89
90
91
92
93
# File 'lib/rubygems/commands/inabox_command.rb', line 84

def geminabox_host=(host)
  config = Gem.configuration.load_file(config_path).merge(:host => host)

  dirname = File.dirname(config_path)
  Dir.mkdir(dirname) unless File.exists?(dirname)

  File.open(config_path, 'w') do |f|
    f.write config.to_yaml
  end
end

#last_minute_requires!Object


36
37
38
39
# File 'lib/rubygems/commands/inabox_command.rb', line 36

def last_minute_requires!
  require 'yaml'
  require File.expand_path("../../../geminabox_client.rb", __FILE__)
end

#send_gems(gemfiles) ⇒ Object


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rubygems/commands/inabox_command.rb', line 56

def send_gems(gemfiles)
  client = GeminaboxClient.new(geminabox_host)

  gemfiles.each do |gemfile|
    say "Pushing #{File.basename(gemfile)} to #{client.url}..."
    begin
      say client.push(gemfile, options)
    rescue GeminaboxClient::Error => e
      alert_error e.message
      terminate_interaction(1)
    end
  end
end

#usageObject


12
13
14
# File 'lib/rubygems/commands/inabox_command.rb', line 12

def usage
  "#{program_name} GEM"
end