Class: Blinkist::Config::DiplomatAdapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/blinkist/config/adapters/diplomat_adapter.rb

Instance Method Summary collapse

Methods inherited from Adapter

instance_for, #preload

Constructor Details

#initialize(env, app_name) ⇒ DiplomatAdapter

Returns a new instance of DiplomatAdapter.



7
8
9
10
11
12
13
14
15
# File 'lib/blinkist/config/adapters/diplomat_adapter.rb', line 7

def initialize(env, app_name)
  super env, app_name

  @items_cache = {}

  Diplomat.configure do |config|
    config.url = "http://172.17.0.1:8500"
  end
end

Instance Method Details

#get(key, default = nil, scope: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/blinkist/config/adapters/diplomat_adapter.rb', line 17

def get(key, default=nil, scope: nil)
  scope ||= @app_name

  diplomat_key = "#{scope}/#{key}"

  unless @items_cache.key? diplomat_key
    @items_cache[diplomat_key] = Diplomat::Kv.get(diplomat_key)
  end

  @items_cache[diplomat_key]
rescue Diplomat::KeyNotFound
  default
end