Class: SecretStore::YamlBackend

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

Direct Known Subclasses

ReadOnlyYamlBackend

Constant Summary collapse

SAVE_FLAGS =
File::RDWR | File::CREAT | File::LOCK_EX | File::LOCK_NB
SAVE_PERMS =
0640

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ YamlBackend

Returns a new instance of YamlBackend.



80
81
82
# File 'lib/secret_store.rb', line 80

def initialize(file_path)
  @file_path = file_path
end

Instance Method Details

#[](key) ⇒ Object



84
85
86
87
# File 'lib/secret_store.rb', line 84

def [](key)
  reload_if_updated
  data[key.to_s]
end

#delete(key) ⇒ Object



109
110
111
112
113
# File 'lib/secret_store.rb', line 109

def delete(key)
  return unless self[key]
  value = delete!(key)
  save && value
end

#insert(key, value) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/secret_store.rb', line 94

def insert(key, value)
  if self[key]
    raise "Key #{key} already stored"
  end

  data[key.to_s] = value
  save
  value
end

#keysObject



89
90
91
92
# File 'lib/secret_store.rb', line 89

def keys
  reload_if_updated
  data.keys
end

#overwrite(key, value) ⇒ Object



104
105
106
107
# File 'lib/secret_store.rb', line 104

def overwrite(key, value)
  delete!(key.to_s)
  insert(key, value)
end

#permits_writes?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/secret_store.rb', line 120

def permits_writes?
  true
end

#reloadObject



115
116
117
118
# File 'lib/secret_store.rb', line 115

def reload
  @data = nil
  data && true
end