Class: Desi::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/desi/downloader.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Downloader

Returns a new instance of Downloader.



11
12
13
14
15
16
# File 'lib/desi/downloader.rb', line 11

def initialize(opts = {})
  @destination_dir = Pathname(opts.fetch(:destination_dir, Desi::LocalInstall.new))
  @host = URI(opts.fetch(:host, 'https://download.elasticsearch.org/'))
  @client = opts.fetch(:http_client_factory, Desi::HttpClient).new(@host)
  @verbose = opts[:verbose]
end

Instance Method Details

#download!(version, opts = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/desi/downloader.rb', line 18

def download!(version, opts = {})
  path = "/elasticsearch/elasticsearch/#{version.filename}"
  destination_name = @destination_dir.join File.basename(version.filename)

  raise "ERROR: File #{destination_name} already present!" if destination_name.exist?

  puts "  * fetching release #{version} from #{@host + path}" if @verbose

  @client.get_file(path, destination_name)

  destination_name
end