Class: TerraspaceBundler::Mod::OrgRepo
- Inherits:
-
Object
- Object
- TerraspaceBundler::Mod::OrgRepo
- Defined in:
- lib/terraspace_bundler/mod/org_repo.rb
Instance Method Summary collapse
- #clean_folder(folder) ⇒ Object
-
#handle_string_with_colon ⇒ Object
user@host:repo [email protected]:org/repo.
-
#initialize(url) ⇒ OrgRepo
constructor
A new instance of OrgRepo.
- #join(*path) ⇒ Object
- #org ⇒ Object
- #org_folder ⇒ Object
- #org_repo_words ⇒ Object
- #repo ⇒ Object
- #repo_folder ⇒ Object
- #strip_dot_git(s) ⇒ Object
Constructor Details
#initialize(url) ⇒ OrgRepo
Returns a new instance of OrgRepo.
3 4 5 |
# File 'lib/terraspace_bundler/mod/org_repo.rb', line 3 def initialize(url) @url = url.sub('ssh://','') # important to copy so dont change the string reference end |
Instance Method Details
#clean_folder(folder) ⇒ Object
38 39 40 41 |
# File 'lib/terraspace_bundler/mod/org_repo.rb', line 38 def clean_folder(folder) folder.sub(%r{.*@},'') # remove user@ .sub(%r{http[s?]://},'') # remove https:// end |
#handle_string_with_colon ⇒ Object
user@host:repo [email protected]:org/repo
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/terraspace_bundler/mod/org_repo.rb', line 44 def handle_string_with_colon host, path = @url.split(':') if path.size == 2 folder, repo = path.split(':') else folder = join(host, File.dirname(path)) repo = File.basename(path) end [folder, repo] end |
#join(*path) ⇒ Object
55 56 57 58 59 |
# File 'lib/terraspace_bundler/mod/org_repo.rb', line 55 def join(*path) path.compact! path[1] = path[1].sub('/','') if path[1].starts_with?('/') path.reject(&:blank?).join('/') end |
#org ⇒ Object
11 12 13 14 |
# File 'lib/terraspace_bundler/mod/org_repo.rb', line 11 def org s = org_folder.split('/').last s ? s.split('/').last : 'none' end |
#org_folder ⇒ Object
16 17 18 |
# File 'lib/terraspace_bundler/mod/org_repo.rb', line 16 def org_folder org_repo_words[-2] # second to last word end |
#org_repo_words ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/terraspace_bundler/mod/org_repo.rb', line 24 def org_repo_words if @url.include?(':') && !@url.match(%r{http[s?]://}) # user@host:repo [email protected]:org/repo folder, repo = handle_string_with_colon else # IE: https://github.com/org/repo, org/repo, etc parts = @url.split('/') folder = parts[0..-2].join('/') repo = parts.last end org_path = clean_folder(folder) repo = strip_dot_git(repo) [org_path, repo] end |
#repo ⇒ Object
7 8 9 |
# File 'lib/terraspace_bundler/mod/org_repo.rb', line 7 def repo org_repo_words[-1] end |
#repo_folder ⇒ Object
20 21 22 |
# File 'lib/terraspace_bundler/mod/org_repo.rb', line 20 def repo_folder org_repo_words.join('/') end |
#strip_dot_git(s) ⇒ Object
61 62 63 |
# File 'lib/terraspace_bundler/mod/org_repo.rb', line 61 def strip_dot_git(s) s.sub(/\.git$/,'') end |