Class: ElasticsearchUpdate::Wizard

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticsearch_update/wizard.rb

Overview

Wizard

ElasticsearchUpdate::Wizard class is used to ask questions to the user using the highline gem.

Parameters

Initilization requires no parameters.

Example

ElasticsearchUpdate::Wizard.new

Instance Method Summary collapse

Instance Method Details

#download_hashObject

download_hash

download_hash is used to construct the hash used by the Downloader

Parameters

Requires no parameters.

Returns

Returns a hash containing the base_url, version, and extension.

Example

wizard = ElasticsearchUpdate::Wizard.new
hash = wizard.download_hash


198
199
200
201
202
203
204
# File 'lib/elasticsearch_update/wizard.rb', line 198

def download_hash
  {
    base_url: 'download.elastic.co',
    version: version,
    extension: extension
  }
end

#elasticsearch_fs_locationObject

elasticsearch_fs_location

elasticsearch_fs_location is used to find where the Elasticsearch binary file is so that we can update from .zip or .tar.gz and successfully start elasticsearch after the update

Parameters

Requires no parameters.

Returns

Returns a string containing path. Ex: ‘/path/to/elasticsearch/’

Example

wizard = ElasticsearchUpdate::Wizard.new
fs_location = wizard.elasticsearch_fs_location


156
157
158
# File 'lib/elasticsearch_update/wizard.rb', line 156

def elasticsearch_fs_location
  ask('In what directory does Elasticsearch run? ', String)
end

#es_location_hashObject

es_location_hash

es_location_hash is used construct the location hash used by other gem classes.

Parameters

Requires no parameters.

Returns

Returns a hash containing the host and port. Ex: { host: ‘localhost’, port: 9200 }

Example

wizard = ElasticsearchUpdate::Wizard.new
location_hash = wizard.es_location_hash


131
132
133
134
135
136
# File 'lib/elasticsearch_update/wizard.rb', line 131

def es_location_hash
  {
    host: host,
    port: port
  }
end

#extensionObject

extension

extension is used to provide a menu to the user asking which file type they would like to use when updating Elasticsearch

Parameters

Requires no parameters.

Returns

Returns @choice which is a string containing either:

  1. ‘.deb’

  2. ‘.rpm’

Example

wizard = ElasticsearchUpdate::Wizard.new
extension = wizard.extension


34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/elasticsearch_update/wizard.rb', line 34

def extension
  choose do |menu|
    menu.prompt = 'Which type of upgrade are we doing?  '

    menu.choice(:deb) { @choice = '.deb' }
    # menu.choice(:zip) { @choice = '.zip' }
    menu.choice(:rpm) { @choice = '.rpm' }
    # menu.choice(:tar) { @choice = '.tar.gz' }
  end

  @choice
end

#hostObject

host

host is used to ask the user the hostname of Elasticsearch so we can interact with it over it’s HTTP API.

Parameters

Requires no parameters.

Returns

Returns a string containing the hostname. Ex: ‘localhost’

Example

wizard = ElasticsearchUpdate::Wizard.new
host = wizard.host


83
84
85
86
87
88
# File 'lib/elasticsearch_update/wizard.rb', line 83

def host
  response = ask('What is your Elasticsearch hostname? (Default: localhost) ', String)
  response = 'localhost' if response == ''

  response
end

#portObject

port

port is used to ask the user the port of Elasticsearch so we can interact with it over it’s HTTP API.

Parameters

Requires no parameters.

Returns

Returns a string containing the port. Ex: ‘9200’

Example

wizard = ElasticsearchUpdate::Wizard.new
port = wizard.port


106
107
108
109
110
111
112
# File 'lib/elasticsearch_update/wizard.rb', line 106

def port
  response = ask('What is your Elasticsearch port? (Default: 9200) ', String)

  response = '9200' if response == ''

  response
end

#sudo_passwordObject

sudo_password

sudo_password is used to get the sudo password for use while installing the updated Elasticsearch files. Echo’s “x” for each keypress.

Parameters

Requires no parameters.

Returns

Returns a string containing the password. Ex: ‘example_password’

Example

wizard = ElasticsearchUpdate::Wizard.new
password = wizard.sudo_password


177
178
179
180
181
# File 'lib/elasticsearch_update/wizard.rb', line 177

def sudo_password
  ask('What password should be used while updating Elasticsearch? ') do |q|
    q.echo = 'x'
  end
end

#versionObject

version

version is used to ask the user which version of Elasticsearch they would like to use.

Parameters

Requires no parameters.

Returns

Returns a string containing a version number. Ex: ‘1.4.3’

Example

wizard = ElasticsearchUpdate::Wizard.new
version = wizard.version


63
64
65
# File 'lib/elasticsearch_update/wizard.rb', line 63

def version
  ask('What version of Elasticsearch should we update to? (major.minor.path) ', String) { |q| q.validate = /\d\.\d\.\d/ }
end