Class: Gem::Commands::SpecificInstallCommand

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

Direct Known Subclasses

GitInstallCommand

Instance Method Summary collapse

Constructor Details

#initializeSpecificInstallCommand

Returns a new instance of SpecificInstallCommand.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rubygems/commands/specific_install_command.rb', line 9

def initialize
  super 'specific_install', description

  add_option('-l', '--location LOCATION', arguments) do |location|
    options[:location] = location
  end

  add_option('-b', '--branch LOCATION', arguments) do |branch|
    options[:branch] = branch
  end

end

Instance Method Details

#argumentsObject



22
23
24
25
# File 'lib/rubygems/commands/specific_install_command.rb', line 22

def arguments
  "LOCATION like http://github.com/rdp/ruby_tutorials_core or git://github.com/rdp/ruby_tutorials_core.git or http://host/gem_name.gem"
  "BRANCH (optional) like beta, or new-feature"
end

#descriptionObject



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

def description
  "Allows you to install an \"edge\" gem straight from its github repository or from a web site"
end

#executeObject



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/rubygems/commands/specific_install_command.rb', line 31

def execute
  require 'tempfile'
  require 'backports'
  require 'fileutils'
  require 'open-uri'
  unless options[:location]
    puts "No location received. Use `gem specific_install -l http://example.com/rdp/specific_install`"
    exit 1
  end
    # 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]
    # http://host/gem_name.gem
    # rdp/specific_install
  dir = Dir.mktmpdir
  begin
    loc = options[:location]
    case loc
    when /^http(.*)\.gem$/
      Dir.chdir dir do
        say "downloading #{loc}"
        gem_name = loc.split("/").last
        download(loc, gem_name)

        if install_gemspec
          success_message
        else
          puts "failed"
        end
      end
    when /\.git$/
     say 'git installing from ' + loc

     system("git clone #{loc} #{dir}")
     install_from_git(dir)
    when %r(.*/.*)
      puts "Installing from [email protected]:#{loc}.git"

      system("git clone [email protected]:#{loc}.git #{dir}")
      install_from_git(dir)
    else
      puts 'Error: must end with .git to be a git repository' +
      'or be in shorthand form: rdp/specific_install'
    end
  ensure
    FileUtils.rm_rf dir
  end

end

#usageObject



27
28
29
# File 'lib/rubygems/commands/specific_install_command.rb', line 27

def usage
  "#{program_name} [LOCATION] [BRANCH]"
end