class Trocla::Stores::Vault

the default vault based store

Attributes

mount[R]
vault[R]

Public Class Methods

new(config,trocla) click to toggle source
Calls superclass method Trocla::Store::new
# File lib/trocla/stores/vault.rb, line 4
def initialize(config,trocla)
  super(config,trocla)
  require 'vault'
  @mount = (config.delete(:mount) || 'kv')
  # load expire support by default
  @vault = Vault::Client.new(config)
end

Public Instance Methods

close() click to toggle source
# File lib/trocla/stores/vault.rb, line 12
def close
end
formats(key) click to toggle source
# File lib/trocla/stores/vault.rb, line 19
def formats(key)
  read(key).keys
end
get(key,format) click to toggle source
# File lib/trocla/stores/vault.rb, line 15
def get(key,format)
  read(key)[format.to_sym]
end

Private Instance Methods

delete_all(key) click to toggle source
# File lib/trocla/stores/vault.rb, line 41
def delete_all(key)
  vault.kv(mount).delete(key)
end
delete_format(key,format) click to toggle source
# File lib/trocla/stores/vault.rb, line 45
def delete_format(key,format)
  old = read(key)
  write(key, old.reject { |k,v| k == format.to_sym })
  old[format.to_sym]
end
read(key) click to toggle source
# File lib/trocla/stores/vault.rb, line 24
def read(key)
  k = vault.kv(mount).read(key)
  k.nil? ? {} : k.data
end
set_format(key,format,value,options) click to toggle source
# File lib/trocla/stores/vault.rb, line 37
def set_format(key,format,value,options)
  write(key, read(key).merge({format.to_sym => value}))
end
set_plain(key,value,options) click to toggle source
# File lib/trocla/stores/vault.rb, line 33
def set_plain(key,value,options)
  set_format(key,'plain',value,options)
end
write(key, value) click to toggle source
# File lib/trocla/stores/vault.rb, line 29
def write(key, value)
  vault.kv(mount).write(key, value)
end