Class: KCommercial::Resources::GitSourceManager
- Inherits:
-
Object
- Object
- KCommercial::Resources::GitSourceManager
- Includes:
- Singleton
- Defined in:
- lib/KCommercialPipeline/core/resource/source/git_source_manager.rb
Instance Attribute Summary collapse
-
#repos_dir ⇒ Object
readonly
Returns the value of attribute repos_dir.
Class Method Summary collapse
-
.shared ⇒ CocoaDepot::Resources::GitSourceManager
The shared manager.
Instance Method Summary collapse
- #home_dir ⇒ Object
-
#name_for_url(url) ⇒ String
Returns a suitable repository name for
url. -
#source_dir(name) ⇒ Pathname
The path of the source with the given name.
-
#source_with_url(url) ⇒ GitSource
Get the git source with name or url.
- #sources ⇒ Object
Instance Attribute Details
#repos_dir ⇒ Object (readonly)
Returns the value of attribute repos_dir.
15 16 17 |
# File 'lib/KCommercialPipeline/core/resource/source/git_source_manager.rb', line 15 def repos_dir @repos_dir end |
Class Method Details
.shared ⇒ CocoaDepot::Resources::GitSourceManager
The shared manager
11 12 13 |
# File 'lib/KCommercialPipeline/core/resource/source/git_source_manager.rb', line 11 def self.shared GitSourceManager.instance end |
Instance Method Details
#home_dir ⇒ Object
17 18 19 20 21 |
# File 'lib/KCommercialPipeline/core/resource/source/git_source_manager.rb', line 17 def home_dir @home_dir ||= Pathname.new(ENV['CP_HOME_DIR'] || '~/.cocoadepot-resources'). @home_dir.mkpath unless @home_dir.exist? @home_dir end |
#name_for_url(url) ⇒ String
Returns a suitable repository name for url.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/KCommercialPipeline/core/resource/source/git_source_manager.rb', line 69 def name_for_url(url) base_from_host_and_path = lambda do |host, path| if host && !host.empty? base = host.split('.')[-2] || host base += '-' else base = '' end base + path.gsub(/.git$/, '').gsub(%r{^/}, '').split('/').join('-') end case url.to_s.downcase when %r{github.com[:/]+(.+)/(.+)} base = Regexp.last_match[1] when %r{^\S+@(\S+)[:/]+(.+)$} host, path = Regexp.last_match.captures base = base_from_host_and_path[host, path] when URI.regexp url = URI(url.downcase) base = base_from_host_and_path[url.host, url.path] else base = url.to_s.downcase end name = base # infinity = 1.0 / 0 # (1..infinity).each do |i| # break unless source_dir(name).exist? # name = "#{base}-#{i}" # end name end |
#source_dir(name) ⇒ Pathname
Returns The path of the source with the given name.
108 109 110 |
# File 'lib/KCommercialPipeline/core/resource/source/git_source_manager.rb', line 108 def source_dir(name) repos_dir + name end |
#source_with_url(url) ⇒ GitSource
Get the git source with name or url
36 37 38 39 40 41 42 43 |
# File 'lib/KCommercialPipeline/core/resource/source/git_source_manager.rb', line 36 def source_with_url(url) name = name_for_url(url) sources[name] ||= begin path = repos_dir.join(name) GitSource.new(url, path) end sources[name] end |
#sources ⇒ Object
29 30 31 |
# File 'lib/KCommercialPipeline/core/resource/source/git_source_manager.rb', line 29 def sources @sources ||= {} end |