Class: Externals::Repository
- Inherits:
-
Object
- Object
- Externals::Repository
- Defined in:
- lib/externals/repository.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #exists? ⇒ Boolean
- #freeze ⇒ Object
-
#initialize(base_dir, name, repo_url, rel_path) ⇒ Repository
constructor
A new instance of Repository.
- #install ⇒ Object
- #is_a_git_repo? ⇒ Boolean
- #is_compressed? ⇒ Boolean
- #is_not_a_git_repo? ⇒ Boolean
- #is_not_compressed? ⇒ Boolean
- #status ⇒ Object
- #unfreeze ⇒ Object
Constructor Details
#initialize(base_dir, name, repo_url, rel_path) ⇒ Repository
Returns a new instance of Repository.
8 9 10 11 12 13 |
# File 'lib/externals/repository.rb', line 8 def initialize(base_dir, name, repo_url, rel_path) @base_dir = base_dir @name = name @repo_url = repo_url @rel_path = rel_path end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/externals/repository.rb', line 6 def name @name end |
Instance Method Details
#exists? ⇒ Boolean
15 16 17 |
# File 'lib/externals/repository.rb', line 15 def exists? File.exist?(repo_path) end |
#freeze ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/externals/repository.rb', line 19 def freeze install unless exists? if is_not_a_git_repo? puts "already frozen: #{@name}" elsif is_a_git_repo? overwrite = true # Conditionally destroy compressed repo if is_compressed? puts "You already have a frozen git snapshot. Overwrite?" overwrite = STDIN.gets.downcase[0..0] == 'y' end Dir.chdir(repo_path) do if overwrite # Make temp directory FileUtils.mkdir_p(temp_path) # Compress .git folder to temp `tar czf #{temp_path}/#{@name}.git.tgz .git` unless $TESTING end # Remove repository's .git folder FileUtils.rm_r('.git') end puts "frozen: #{@name}" end end |
#install ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/externals/repository.rb', line 44 def install # Create directory that we will clone into unless File.exist?(checkout_path) FileUtils.mkdir_p(checkout_path) end Dir.chdir(checkout_path) do # Remove repository if exists FileUtils.rm_rf(@name) # Clone repository `git clone #{@repo_url} #{@name}` unless $TESTING end end |
#is_a_git_repo? ⇒ Boolean
57 58 59 |
# File 'lib/externals/repository.rb', line 57 def is_a_git_repo? File.exist?("#{repo_path}/.git") end |
#is_compressed? ⇒ Boolean
65 66 67 |
# File 'lib/externals/repository.rb', line 65 def is_compressed? File.exists?("#{temp_path}/#{@name}.git.tgz") end |
#is_not_a_git_repo? ⇒ Boolean
61 62 63 |
# File 'lib/externals/repository.rb', line 61 def is_not_a_git_repo? !is_a_git_repo? end |
#is_not_compressed? ⇒ Boolean
69 70 71 |
# File 'lib/externals/repository.rb', line 69 def is_not_compressed? !is_compressed? end |
#status ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/externals/repository.rb', line 73 def status if exists? puts "#{is_a_git_repo? ? "not frozen" : "frozen and #{is_compressed? ? "has" : "does not have"} a snapshot"}: #{@name}" else puts "does not exist and #{is_compressed? ? "has" : "does not have"} a snapshot: #{@name}" end end |
#unfreeze ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/externals/repository.rb', line 81 def unfreeze if is_a_git_repo? puts "already unfrozen: #{@name}" elsif !exists? install puts "#{@name} unfrozen" elsif is_not_a_git_repo? if is_compressed? Dir.chdir(temp_path) do # Decompress git snapshot `tar xzf #{@name}.git.tgz` unless $TESTING # Move back to repo FileUtils.mv(".git", repo_path) # Remove snapshot FileUtils.rm_f("#{@name}.git.tgz") end else # Clone fresh repo if no snapshot found install end puts "unfrozen: #{@name}" end end |