Class: Gill::Import
- Inherits:
-
Object
- Object
- Gill::Import
- Defined in:
- lib/gill/import.rb
Instance Method Summary collapse
-
#add(category, repo_name, git_uri, path) ⇒ Object
Add Repository.
-
#check_move_import(basename, repo_name, path) ⇒ Object
Check, Move & import.
-
#find_repo(path, repo_name, parent) ⇒ Object
Find Repo.
-
#git_uri_for(path) ⇒ String
Git URI For Path.
-
#has_git_config?(path) ⇒ true, false
Has Git?.
-
#has_git_folder?(path) ⇒ true, false
Has Git Folder.
-
#import(path = nil) ⇒ Object
Import.
-
#initialize ⇒ Import
constructor
A new instance of Import.
-
#move_root_repos_to_default_path(source, destination) ⇒ Object
Move Repository.
-
#repo_in_root(folder) ⇒ true, false
Repository In Root.
-
#search_folder(folder) ⇒ Object
Search Folder.
- #update_cache ⇒ Object
Methods included from Helper
#ask, #basename, #blue, #folder_empty?, #green, #parent, #red
Constructor Details
Instance Method Details
#add(category, repo_name, git_uri, path) ⇒ Object
Add Repository
144 145 146 147 148 149 150 |
# File 'lib/gill/import.rb', line 144 def add(category,repo_name,git_uri,path) if @updated_cache[:categories].has_key?(category.to_s.downcase.to_sym) @updated_cache[:categories][category.to_s.downcase.to_sym].merge!({repo_name.to_sym => {:repo => git_uri, :path => path}}) else @updated_cache[:categories][category.to_s.downcase.to_sym] = { repo_name.to_sym => { :repo => git_uri, :path => path }} end end |
#check_move_import(basename, repo_name, path) ⇒ Object
Check, Move & import
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/gill/import.rb', line 75 def check_move_import(basename,repo_name,path) git_uri = git_uri_for(path) if repo_in_root(basename) prompt = "Do you want to move #{basename(Gill.config.source_path)}/#{basename(repo_name)} to", "#{basename(Gill.config.source_path)}/#{basename(Gill.config.default_path)}/#{basename(repo_name)}?" ask prompt, :default => false do move_root_repos_to_default_path(path,File.join(Gill.config.source_path, basename(Gill.config.default_path), repo_name)) add(basename(Gill.config.default_path),repo_name,git_uri, File.join(Gill.config.source_path, basename(Gill.config.default_path), repo_name)) end else add(basename,repo_name,git_uri,path) end end |
#find_repo(path, repo_name, parent) ⇒ Object
Find Repo
40 41 42 43 44 45 46 47 48 |
# File 'lib/gill/import.rb', line 40 def find_repo(path,repo_name,parent) if has_git_folder?(path) check_move_import(basename(parent.path), repo_name, path) if has_git_config?(path) else import(path) end end |
#git_uri_for(path) ⇒ String
Git URI For Path
125 126 127 128 129 130 131 |
# File 'lib/gill/import.rb', line 125 def git_uri_for(path) File.open(File.join(path, '.git', 'config'), 'r') do |file| @git_uri = file.read[/url\s+\=\s+(\S+)/m,1] file.close end @git_uri end |
#has_git_config?(path) ⇒ true, false
Has Git?
103 104 105 106 |
# File 'lib/gill/import.rb', line 103 def has_git_config?(path) return true if File.exist?(File.join(path, '.git', 'config')) false end |
#has_git_folder?(path) ⇒ true, false
Has Git Folder
path contains a .git folder.
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/gill/import.rb', line 178 def has_git_folder?(path) temp = Dir.new(path) if temp.entries.include?('.git') temp.close return true else return false end end |
#import(path = nil) ⇒ Object
Import
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gill/import.rb', line 20 def import(path=nil) if path.nil? folder = Gill.config.source_path else folder = path end search_folder(folder) end |
#move_root_repos_to_default_path(source, destination) ⇒ Object
Move Repository
114 115 116 |
# File 'lib/gill/import.rb', line 114 def move_root_repos_to_default_path(source,destination) FileUtils.mv(source,destination) end |
#repo_in_root(folder) ⇒ true, false
Repository In Root
is in the root dir.
165 166 167 168 |
# File 'lib/gill/import.rb', line 165 def repo_in_root(folder) return true if folder.to_s == basename(Gill.config.source_path).to_s false end |
#search_folder(folder) ⇒ Object
Search Folder
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/gill/import.rb', line 55 def search_folder(folder) current_folder = Dir.new(folder) current_folder.entries.each do |file| next if %w(. ..).include?(file) path = File.join(current_folder.path, file) find_repo(path,file,current_folder) if File.directory?(path) end end |