Class: Serverspec::Type::ConsulBase

Inherits:
ApiBase
  • Object
show all
Defined in:
lib/serverspec_extra_types/types/consul_base.rb

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, acl_token = nil, options = {}) ⇒ ConsulBase

Returns a new instance of ConsulBase.



9
10
11
12
13
# File 'lib/serverspec_extra_types/types/consul_base.rb', line 9

def initialize(name = nil, acl_token = nil, options = {})
  super(name, options)
  @token = acl_token
  @url_base = property[:variables][:consul_url] || 'http://localhost:8500'
end

Instance Method Details

#[](key) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/serverspec_extra_types/types/consul_base.rb', line 15

def [](key)
  value = inspection
  key.split('.').each do |k|
    is_index = k.start_with?('[') && k.end_with?(']')
    value = value[is_index ? k[1..-2].to_i : k]
  end
  value
end

#inspectionObject



28
29
30
# File 'lib/serverspec_extra_types/types/consul_base.rb', line 28

def inspection
  @inspection ||= ::MultiJson.load(get_inspection.stdout)[0]
end

#urlObject



24
25
26
# File 'lib/serverspec_extra_types/types/consul_base.rb', line 24

def url
  @url_base
end