Class: Elasticsearch::Embedded::Downloader

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

Constant Summary collapse

TEMPORARY_PATH =

Default temporary path used by downloader

defined?(::Rails) ? ::Rails.root.join('tmp') : Dir.tmpdir
DEFAULT_VERSION =

Default version of elasticsearch to download

'1.4.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Downloader

Returns a new instance of Downloader.



18
19
20
21
# File 'lib/elasticsearch/embedded/downloader.rb', line 18

def initialize(args = {})
  @version = args[:version] || ENV['ELASTICSEARCH_VERSION'] || DEFAULT_VERSION
  @path = args[:path] || ENV['ELASTICSEARCH_DOWNLOAD_PATH'] || TEMPORARY_PATH
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



16
17
18
# File 'lib/elasticsearch/embedded/downloader.rb', line 16

def path
  @path
end

#versionObject (readonly)

Returns the value of attribute version.



16
17
18
# File 'lib/elasticsearch/embedded/downloader.rb', line 16

def version
  @version
end

Class Method Details

.download(arguments = {}) ⇒ Object

Download elasticsearch distribution and unzip it in the specified temporary path



24
25
26
# File 'lib/elasticsearch/embedded/downloader.rb', line 24

def self.download(arguments = {})
  new(arguments).perform
end

Instance Method Details

#dist_folderObject



42
43
44
# File 'lib/elasticsearch/embedded/downloader.rb', line 42

def dist_folder
  @dist_folder ||= final_path.gsub /\.zip\Z/, ''
end

#downloaded?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/elasticsearch/embedded/downloader.rb', line 34

def downloaded?
  File.exists?(final_path)
end

#executableObject



54
55
56
# File 'lib/elasticsearch/embedded/downloader.rb', line 54

def executable
  @executable ||= File.join(dist_folder, 'bin', 'elasticsearch')
end

#extracted?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/elasticsearch/embedded/downloader.rb', line 38

def extracted?
  File.directory?(dist_folder)
end

#final_pathObject



46
47
48
# File 'lib/elasticsearch/embedded/downloader.rb', line 46

def final_path
  @final_path ||= File.join(working_dir, "elasticsearch-#{version}.zip")
end

#performObject



28
29
30
31
32
# File 'lib/elasticsearch/embedded/downloader.rb', line 28

def perform
  download_file
  extract_file
  self
end

#working_dirObject



50
51
52
# File 'lib/elasticsearch/embedded/downloader.rb', line 50

def working_dir
  @working_dir ||= File.realpath(path)
end