Class: Gem::Commands::FromGitCommand

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

Instance Method Summary collapse

Constructor Details

#initializeFromGitCommand

Returns a new instance of FromGitCommand.



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

def initialize
  super 'from_git', description

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

end

Instance Method Details

#argumentsObject



18
19
20
21
# File 'lib/rubygems/commands/from_git_command.rb', line 18

def arguments
  "PATH         https://github.com/user/repo.git"
  "BRANCH       Git branch to use"
end

#descriptionObject



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

def description
  "Allows you to install gem from git repository"
end

#executeObject



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
# File 'lib/rubygems/commands/from_git_command.rb', line 27

def execute
  require 'fileutils'
  require 'tempfile'
  require 'colored'

  destination = Dir.mktmpdir

  begin
    error "No repository specified" unless options[:args].length > 0

    run "git clone #{options[:args][0]} #{destination}", "Error cloning repository"

    Dir.chdir destination do
      if options[:branch]
        run "git checkout #{options[:branch]}", "Error checkouting branch"
      end

      run "gem build *.gemspec", "Error building gem"
      run "gem install *.gem",    "Error installing gem"
    end

    puts "Done".green
    exit 0
  ensure
    FileUtils.rm_rf destination
  end
end

#usageObject



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

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