lib/terraspace_bundler/mod/concerns/notation_concern.rb in terraspace-bundler-0.4.4 vs lib/terraspace_bundler/mod/concerns/notation_concern.rb in terraspace-bundler-0.5.0
- old
+ new
@@ -9,20 +9,22 @@
def remove_ref_notation(source)
source.sub(/\?.*/,'')
end
def remove_subfolder_notation(source)
- parts = clean_notation(source).split('//')
+ clean = clean_notation(source)
+ parts = clean.split('//')
if parts.size == 2 # has subfolder
source.split('//')[0..-2].join('//') # remove only subfolder, keep rest of original source
else
source
end
end
def subfolder(source)
- parts = clean_notation(source).split('//')
+ clean = clean_notation(source)
+ parts = clean.split('//')
if parts.size == 2 # has subfolder
remove_ref_notation(parts.last)
end
end
@@ -33,10 +35,25 @@
params = URI::decode_www_form(uri.query).to_h # if you are in 2.1 or later version of Ruby
params['ref']
end
end
+
def clean_notation(source)
- source.sub(/.*::/,'').sub(%r{http[s?]://},'').sub(%r{git@(.*?):},'') # also remove git@ notation
+ clean = source
+ .sub(/.*::/,'') # remove git::
+ .sub(%r{http[s?]://},'') # remove https://
+ .sub(%r{git@(.*?):},'') # remove git@word
+ remove_host(clean)
+ end
+
+ def remove_host(clean)
+ return clean unless clean.include?('ssh://')
+ if clean.count(':') == 1
+ uri = URI(clean)
+ uri.path
+ else
+ clean.split(':').last
+ end
end
end
end