Class: Gem::Commands::GitInstallCommand

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

Instance Method Summary collapse

Constructor Details

#initializeGitInstallCommand

Returns a new instance of GitInstallCommand.



9
10
11
12
13
14
# File 'lib/rubygems/commands/git_install_command.rb', line 9

def initialize
  super 'git_install', description
  add_option('-g', '--git_location GIT_LOCATION', arguments) do |git_location|
    options[:git_location] = git_location
  end
end

Instance Method Details

#argumentsObject



16
17
18
# File 'lib/rubygems/commands/git_install_command.rb', line 16

def arguments
  "GIT_LOCATION like http://github.com/rdp/ruby_tutorials_core or git://github.com/rdp/ruby_tutorials_core.git"
end

#descriptionObject



5
6
7
# File 'lib/rubygems/commands/git_install_command.rb', line 5

def description
  "Allows you to install an \"edge\" gem straight from its github repository (like -g  git://github.com/rdp/ruby_tutorials_core.git)"
end

#executeObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rubygems/commands/git_install_command.rb', line 24

def execute
  require 'tempfile'
  require 'backports'
  require 'fileutils'
  if loc = options[:git_location]
    # options are
    # http://github.com/githubsvnclone/rdoc.git
    # git://github.com/githubsvnclone/rdoc.git
    # [email protected]:rdp/install_from_git.git
    # http://github.com/rdp/install_from_git [later]
    if !loc.end_with?('.git')
     say 'error: must end with .git to be a git repository'
    else
     say 'git installing from ' + loc
     dir = Dir.mktmpdir
     system("git clone #{loc} #{dir}")
     Dir.chdir dir do
      for command in ['', 'rake gemspec', 'rake gem', 'rake build', 'rake package'] do
        system command
        if install_gemspec
          puts 'gem installed'
          return
        end          
      end
     end
     FileUtils.rm_rf dir # just in case
    end
     
  else
    say 'git location is required'
  end
end

#usageObject



20
21
22
# File 'lib/rubygems/commands/git_install_command.rb', line 20

def usage
  "#{program_name} [GIT_LOCATION]"
end