Class: Elasticsearch::Embedded::Downloader
- Inherits:
-
Object
- Object
- Elasticsearch::Embedded::Downloader
- 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
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.download(arguments = {}) ⇒ Object
Download elasticsearch distribution and unzip it in the specified temporary path.
Instance Method Summary collapse
- #dist_folder ⇒ Object
- #downloaded? ⇒ Boolean
- #executable ⇒ Object
- #extracted? ⇒ Boolean
- #final_path ⇒ Object
-
#initialize(args = {}) ⇒ Downloader
constructor
A new instance of Downloader.
- #perform ⇒ Object
- #working_dir ⇒ Object
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
#path ⇒ Object (readonly)
Returns the value of attribute path.
16 17 18 |
# File 'lib/elasticsearch/embedded/downloader.rb', line 16 def path @path end |
#version ⇒ Object (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_folder ⇒ Object
42 43 44 |
# File 'lib/elasticsearch/embedded/downloader.rb', line 42 def dist_folder @dist_folder ||= final_path.gsub /\.zip\Z/, '' end |
#downloaded? ⇒ Boolean
34 35 36 |
# File 'lib/elasticsearch/embedded/downloader.rb', line 34 def downloaded? File.exists?(final_path) end |
#executable ⇒ Object
54 55 56 |
# File 'lib/elasticsearch/embedded/downloader.rb', line 54 def executable @executable ||= File.join(dist_folder, 'bin', 'elasticsearch') end |
#extracted? ⇒ Boolean
38 39 40 |
# File 'lib/elasticsearch/embedded/downloader.rb', line 38 def extracted? File.directory?(dist_folder) end |
#final_path ⇒ Object
46 47 48 |
# File 'lib/elasticsearch/embedded/downloader.rb', line 46 def final_path @final_path ||= File.join(working_dir, "elasticsearch-#{version}.zip") end |
#perform ⇒ Object
28 29 30 31 32 |
# File 'lib/elasticsearch/embedded/downloader.rb', line 28 def perform download_file extract_file self end |
#working_dir ⇒ Object
50 51 52 |
# File 'lib/elasticsearch/embedded/downloader.rb', line 50 def working_dir @working_dir ||= File.realpath(path) end |