Class: Chrysalis::VCS::HTTP::Repository
- Inherits:
-
Repository
- Object
- Repository
- Chrysalis::VCS::HTTP::Repository
- Defined in:
- lib/chrysalis/vcs/http/repository.rb
Overview
Implements support for downloading dependencies from a web server.
Repositories of this type are identified by http:// URLs.
Example:
- http://www.example.com/dist/libfoo-1.2.8.tar.gz
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(url, params = {}) ⇒ Repository
constructor
A new instance of Repository.
- #retrieve(to = '.') ⇒ Object
Methods inherited from Repository
Constructor Details
#initialize(url, params = {}) ⇒ Repository
Returns a new instance of Repository.
26 27 28 29 |
# File 'lib/chrysalis/vcs/http/repository.rb', line 26 def initialize(url, params = {}) @url = url @params = params end |
Class Method Details
.retrieves?(url, params = {}) ⇒ Boolean
20 21 22 23 |
# File 'lib/chrysalis/vcs/http/repository.rb', line 20 def self.retrieves?(url, params = {}) uri = URI::parse(url) return (uri.scheme == 'http' || uri.scheme == 'https') end |
Instance Method Details
#retrieve(to = '.') ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/chrysalis/vcs/http/repository.rb', line 31 def retrieve(to = '.') path = Pathname.new(to).join(download_to) raise IOError, "Refusing to overwrite existing path. (path: #{path})" if path.exist? unless @params[:noop] puts "" puts "Downloading #{@url} ..." location = URI::parse(@url) Net::HTTP.start(location.host, location.port) do |http| mode = (RUBY_PLATFORM.match(/mswin/) ? 'wb' : 'w') ::File.open(path, mode) do |f| http.get(location.path) do |stream| f.write stream end end end end extract_path = Archive.extract(path.to_s, to, @params) WorkingCopy.new(:url => @url, :path => extract_path) end |