Class: Gem::Commands::SpecificInstallCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::SpecificInstallCommand
- Defined in:
- lib/rubygems/commands/specific_install_command.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #arguments ⇒ Object
- #change_to_branch(branch) ⇒ Object
- #description ⇒ Object
- #determine_source_and_install ⇒ Object
- #download(full_url, output_name) ⇒ Object
- #execute ⇒ Object
- #find_or_build_gem ⇒ Object
- #gem_name ⇒ Object
- #gemfile(name = '**/*.gem') ⇒ Object
- #gemspec_exists?(name = "*.gemspec") ⇒ Boolean
- #gemspec_file(name = "*.gemspec") ⇒ Object
-
#initialize(output = STDOUT) ⇒ SpecificInstallCommand
constructor
A new instance of SpecificInstallCommand.
- #install_from_git(dir) ⇒ Object
- #install_gem ⇒ Object
- #install_gemspec ⇒ Object
- #install_git ⇒ Object
- #install_http_repo ⇒ Object
- #install_shorthand ⇒ Object
- #set_branch ⇒ Object
- #set_location ⇒ Object
- #success_message ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(output = STDOUT) ⇒ SpecificInstallCommand
Returns a new instance of SpecificInstallCommand.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 15 def initialize(output=STDOUT) super 'specific_install', description @output = output add_option('-l', '--location LOCATION', arguments) do |location, | [:location] = location end add_option('-b', '--branch LOCATION', arguments) do |branch, | [:branch] = branch end end |
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
9 10 11 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 9 def output @output end |
Instance Method Details
#arguments ⇒ Object
29 30 31 32 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 29 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\n" + "BRANCH (optional) like beta, or new-feature" end |
#change_to_branch(branch) ⇒ Object
192 193 194 195 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 192 def change_to_branch(branch) system("git checkout #{branch}") system("git branch") end |
#description ⇒ Object
11 12 13 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 11 def description "Allows you to install an 'edge' gem straight from its github repository or from a web site" end |
#determine_source_and_install ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 50 def determine_source_and_install case @loc when /^https?(.*)\.gem$/ install_gem when /\.git$/ install_git when /^https?(.*)$/ install_http_repo # install_gem when %r(.*/.*) install_shorthand else warn 'Error: must end with .git to be a git repository' + 'or be in shorthand form: rdp/specific_install' end end |
#download(full_url, output_name) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 110 def download( full_url, output_name ) File.open(output_name, "wb") do |output_file| uri = URI.parse(full_url) output_file.write(uri.read) end end |
#execute ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 38 def execute @loc ||= set_location @branch ||= set_branch if set_branch if @loc.nil? raise ArgumentError, "No location received. Use like `gem specific_install -l http://example.com/rdp/specific_install`" end Dir.mktmpdir do |dir| @dir = dir determine_source_and_install end end |
#find_or_build_gem ⇒ Object
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 161 def find_or_build_gem if gemspec_exists? gemspec = Gem::Specification.load(gemspec_file) Gem::Package.build gemspec elsif gemfile gemfile else nil end end |
#gem_name ⇒ Object
90 91 92 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 90 def gem_name @gem_name ||= @loc.split("/").last end |
#gemfile(name = '**/*.gem') ⇒ Object
184 185 186 187 188 189 190 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 184 def gemfile(name = '**/*.gem') if Dir[name].empty? false else Dir[name][0] end end |
#gemspec_exists?(name = "*.gemspec") ⇒ Boolean
176 177 178 179 180 181 182 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 176 def gemspec_exists?(name = "*.gemspec") if gemspec_file(name) File.exists?(gemspec_file(name)) else false end end |
#gemspec_file(name = "*.gemspec") ⇒ Object
172 173 174 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 172 def gemspec_file(name = "*.gemspec") Dir[name][0] end |
#install_from_git(dir) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 117 def install_from_git(dir) Dir.chdir dir do change_to_branch(@branch) if @branch system("git submodule update --init --recursive") # issue 25 # reliable method if install_gemspec exit 0 end # legacy methods ['', 'rake gemspec', 'rake gem', 'rake build', 'rake package'].each do |command| puts "attempting #{command}..." system command if install_gemspec exit 0 end end end end |
#install_gem ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 67 def install_gem Dir.chdir @dir do output.puts "downloading #{@loc}" download(@loc, gem_name) if install_gemspec else output.puts "Failed" end end end |
#install_gemspec ⇒ Object
151 152 153 154 155 156 157 158 159 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 151 def install_gemspec gem = find_or_build_gem if gem inst = Gem::DependencyInstaller.new inst.install gem else nil end end |
#install_git ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 94 def install_git output.puts 'git installing from ' + @loc redirect_for_specs = ENV.fetch( "SPECIFIC_INSTALL_SPEC" ) { "" } system("git clone #{@loc} #{@dir} #{redirect_for_specs}") install_from_git(@dir) end |
#install_http_repo ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 80 def install_http_repo output.puts 'http installing from ' + @loc @loc = [@loc, '.git'].join unless @loc[/\.git$/] redirect_for_specs = ENV.fetch( "SPECIFIC_INSTALL_SPEC" ) { "" } system("git clone #{@loc} #{@dir} #{redirect_for_specs}") install_from_git(@dir) end |
#install_shorthand ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 102 def install_shorthand output.puts "Installing from [email protected]:#{@loc}.git" redirect_for_specs = ENV.fetch( "SPECIFIC_INSTALL_SPEC" ) { "" } system("git clone [email protected]:#{@loc}.git #{@dir} #{redirect_for_specs}") install_from_git(@dir) end |
#set_branch ⇒ Object
143 144 145 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 143 def set_branch [:branch] || [:args][1] end |
#set_location ⇒ Object
139 140 141 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 139 def set_location [:location] || [:args][0] end |
#success_message ⇒ Object
147 148 149 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 147 def output.puts 'Successfully installed' end |
#usage ⇒ Object
34 35 36 |
# File 'lib/rubygems/commands/specific_install_command.rb', line 34 def usage "#{program_name} [LOCATION] [BRANCH] (or command line options for the same)" end |