Sha256: 4e1cd760c79b3bd5bd49eb03850ad2dd16f0ffa684be6bbf81ae5a5092c08ac2
Contents?: true
Size: 1.53 KB
Versions: 1
Compression:
Stored size: 1.53 KB
Contents
class TerraspaceBundler::Mod class OrgRepo def initialize(url) @url = url.sub('ssh://','') # important to copy so dont change the string reference end def repo org_repo_words[-1] end def org s = org_folder.split('/').last s ? s.split('/').last : 'none' end def org_folder org_repo_words[-2] # second to last word end def repo_folder org_repo_words.join('/') end def org_repo_words if @url.include?(':') && !@url.match(%r{http[s?]://}) # user@host:repo git@github.com: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 def clean_folder(folder) folder.sub(%r{.*@},'') # remove user@ .sub(%r{http[s?]://},'') # remove https:// end # user@host:repo git@github.com:org/repo 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 def join(*path) path.compact! path[1] = path[1].sub('/','') if path[1].starts_with?('/') path.reject(&:blank?).join('/') end def strip_dot_git(s) s.sub(/\.git$/,'') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
terraspace-bundler-0.5.0 | lib/terraspace_bundler/mod/org_repo.rb |