Class: Elasticshell::ElasticsearchConfigFile

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticshell/utils/es_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ElasticsearchConfigFile

Returns a new instance of ElasticsearchConfigFile.



9
10
11
# File 'lib/elasticshell/utils/es_config.rb', line 9

def initialize path
  self.path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/elasticshell/utils/es_config.rb', line 7

def path
  @path
end

Instance Method Details

#configObject



17
18
19
# File 'lib/elasticshell/utils/es_config.rb', line 17

def config
  @config ||= YAML.load(File.new(path))
end

#hostsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/elasticshell/utils/es_config.rb', line 21

def hosts
  return @hosts if @hosts
  Elasticshell.debug("Looking for Elasticsearch hosts in #{path}...")
  unicast_hosts   = (config["discovery"]["zen"]["ping"]["unicast"]["hosts"] rescue nil)
  unicast_hosts ||= (config["discovery"]["zen"]["ping"]["unicast.hosts"]    rescue nil)
  unicast_hosts ||= (config["discovery"]["zen"]["ping.unicast.hosts"]       rescue nil)
  unicast_hosts ||= (config["discovery"]["zen.ping.unicast.hosts"]          rescue nil)
  unicast_hosts ||= (config["discovery"]["zen.ping.unicast.hosts"]          rescue nil)
  unicast_hosts ||= (config["discovery.zen.ping.unicast.hosts"]             rescue nil)
  @hosts = case unicast_hosts
  when String then unicast_hosts.split(',').map(&:strip)
  when Array  then unicast_hosts.map(&:to_s).map(&:strip)
  else
    []
  end.map do |unicast_host|
    host(unicast_host)
  end
end

#http_portObject



40
41
42
43
44
45
46
47
48
# File 'lib/elasticshell/utils/es_config.rb', line 40

def http_port
  return @http_port if @http_port
  port_string   = (config["http"]["port"] rescue nil)
  port_string ||= (config["http.port"]    rescue nil)
  @http_port = case port_string
  when String, Fixnum then port_string.to_i
  else 9200
  end
end

#readable?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/elasticshell/utils/es_config.rb', line 13

def readable?
  File.exist?(path) && File.readable?(path)
end