2015-08-13 03:47:02 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'uri'
|
2015-08-13 05:34:24 +00:00
|
|
|
require 'tempfile'
|
|
|
|
require 'open-uri'
|
|
|
|
require 'vulcano/targets/zip'
|
2015-08-13 03:47:02 +00:00
|
|
|
|
2015-08-13 05:34:24 +00:00
|
|
|
module Vulcano::Targets
|
|
|
|
class UrlHelper
|
|
|
|
def handles?(target)
|
|
|
|
uri = URI.parse(target)
|
2015-09-06 20:40:46 +00:00
|
|
|
return false if uri.nil? or uri.scheme.nil?
|
2015-08-13 05:34:24 +00:00
|
|
|
%{ http https }.include? uri.scheme
|
|
|
|
end
|
|
|
|
|
|
|
|
def resolve(target)
|
2015-09-09 10:18:42 +00:00
|
|
|
return nil unless target.start_with? 'https://github.com' and
|
|
|
|
target.end_with? '.git'
|
|
|
|
|
|
|
|
url = target.sub(/.git$/, '') + '/archive/master.zip'
|
|
|
|
resolve_zip(url)
|
2015-08-13 05:34:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def resolve_zip(url)
|
|
|
|
zipfile = Tempfile.new('vulcano-dl-')
|
|
|
|
zipfile.binmode
|
|
|
|
zipfile.write(open(url).read)
|
|
|
|
zipfile.rewind
|
2015-08-13 05:45:42 +00:00
|
|
|
content = ZipHelper.new.resolve(zipfile.path)
|
2015-08-13 05:34:24 +00:00
|
|
|
zipfile.close
|
|
|
|
zipfile.unlink
|
2015-09-03 18:45:37 +00:00
|
|
|
content
|
2015-08-13 05:34:24 +00:00
|
|
|
end
|
2015-08-13 03:47:02 +00:00
|
|
|
end
|
|
|
|
|
2015-08-13 05:34:24 +00:00
|
|
|
Vulcano::Targets.add_module('url', UrlHelper.new)
|
|
|
|
end
|