Class: PerfectWorld::Storage
- Inherits:
-
Object
- Object
- PerfectWorld::Storage
- Defined in:
- lib/perfect_world/storage.rb
Class Method Summary collapse
-
.dump(data, recipient, path) ⇒ Object
Writes data into an encrypted file.
-
.find_key(term = nil) ⇒ Object
Finds a secret key in the key ring.
-
.load(path) ⇒ Object
Loads data from an encrypted file.
Class Method Details
.dump(data, recipient, path) ⇒ Object
Writes data into an encrypted file.
PerfectWorld::Storage.dump([1, 2], 'gpguid', /path/to/file.yml.gpg')
Raises PerfectWorld::Error on error.
27 28 29 |
# File 'lib/perfect_world/storage.rb', line 27 def dump(data, recipient, path) commit(encrypt(serialize(data), find_key(recipient)), path) end |
.find_key(term = nil) ⇒ Object
Finds a secret key in the key ring.
Returns GPGME::Key or raises PerfectWorld::KeyNotFound.
34 35 36 |
# File 'lib/perfect_world/storage.rb', line 34 def find_key(term = nil) GPGME::Key.find(:secrect, term).first || raise(KeyNotFound, term) end |
.load(path) ⇒ Object
Loads data from an encrypted file.
PerfectWorld::Storage.load('path/to/file.yml.gpg') #=> [1, 2]
Returns the data.
16 17 18 19 20 |
# File 'lib/perfect_world/storage.rb', line 16 def load(path) open(path) do |file| deserialize(decrypt(file)) end end |