Module: GitGem::Action
- Defined in:
- lib/gitgem/action.rb
Class Method Summary collapse
- .add(repo_alias = nil, repo) ⇒ Object
- .install(repo_alias, gem_dir) ⇒ Object
- .remove(repo_alias) ⇒ Object
- .uninstall(repo_alias, gem_dir) ⇒ Object
Class Method Details
.add(repo_alias = nil, repo) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gitgem/action.rb', line 10 def add(repo_alias = nil, repo) repo_alias = repo if repo_alias.nil? || repo_alias.empty? abort("Alias could not start with '.'") if repo_alias.start_with?(".") should_add = true result = read_alias(repo_alias) unless result.nil? puts "#{repo_alias} is already exist: #{result}" printf "replace? (y/n): " input = readline if input.start_with?("y") remove(repo_alias) should_add = true else should_add = false end end system("echo #{repo_alias}=#{repo} >> #{alias_path}") if should_add end |
.install(repo_alias, gem_dir) ⇒ Object
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 |
# File 'lib/gitgem/action.rb', line 39 def install(repo_alias, gem_dir) abort("Please specify alias like alias/gem") if repo_alias.nil? || repo_alias.empty? result = read_alias(repo_alias) abort("Could not find alias named #{repo_alias}, please check again.") if result.nil? repo = result.gsub("#{repo_alias}=", "") alias_dir = File.join(base_dir, repo_alias) repo_dir = File.join(alias_dir, File.basename(repo, ".git")) pwd = Dir.pwd unless File.exist?(alias_dir) Dir.chdir(base_dir) FileUtils.mkdir_p(alias_dir) Dir.chdir(alias_dir) system("git clone -q #{repo}") end Dir.chdir(repo_dir) system("git checkout -- .") system("git pull -q") gems = Dir.glob(File.join(gem_dir, "*.gem")) abort("Could not find gem in #{File.join(Dir.pwd, gem_dir)}") if gems.nil? || gems.empty? gems.each do |gem| system("gem install #{gem}") end Dir.chdir(pwd) end |
.remove(repo_alias) ⇒ Object
33 34 35 36 37 |
# File 'lib/gitgem/action.rb', line 33 def remove(repo_alias) result = read_alias(repo_alias) FileUtils.rm_rf(File.join(base_dir, repo_alias)) unless result.nil? system("sed -i '' '/#{repo_alias}=/d' #{alias_path}") end |
.uninstall(repo_alias, gem_dir) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/gitgem/action.rb', line 69 def uninstall(repo_alias, gem_dir) abort("Please specify alias like alias/gem") if repo_alias.nil? || repo_alias.empty? result = read_alias(repo_alias) abort("Could not find alias named #{repo_alias}, please check again.") if result.nil? repo = result.gsub("#{repo_alias}=", "") alias_dir = File.join(base_dir, repo_alias) repo_dir = File.join(alias_dir, File.basename(repo, ".git")) gems = Dir.glob(File.join(repo_dir, gem_dir, "*.gem")) abort("Could not find gem in #{File.join(repo_dir, gem_dir)}") if gems.nil? || gems.empty? gems.each do |gem| gem_name = File.basename(gem, ".gem").split("-")[0...-1].join("-") system("gem uninstall #{gem_name}") end end |