Class: KStor::Crypto::ArmoredHash
- Inherits:
-
ArmoredValue
- Object
- ArmoredValue
- KStor::Crypto::ArmoredHash
- Defined in:
- lib/kstor/crypto/armored_value.rb
Overview
A Hash that can be easily serialized to ASCII chars.
Uses JSON as intermediary data format.
Direct Known Subclasses
Class Method Summary collapse
-
.from_hash(hash) ⇒ KStor::Crypto::ArmoredHash
Create from Ruby Hash.
Instance Method Summary collapse
-
#[](key) ⇒ Any?
Access value for this key.
-
#[]=(key, val) ⇒ Object
Set value for a key.
-
#to_hash ⇒ Hash
Convert to Ruby Hash.
Methods inherited from ArmoredValue
from_binary, #initialize, #to_ascii, #to_binary
Constructor Details
This class inherits a constructor from KStor::Crypto::ArmoredValue
Class Method Details
.from_hash(hash) ⇒ KStor::Crypto::ArmoredHash
Create from Ruby Hash.
52 53 54 |
# File 'lib/kstor/crypto/armored_value.rb', line 52 def self.from_hash(hash) from_binary(hash.to_json) end |
Instance Method Details
#[](key) ⇒ Any?
Access value for this key.
67 68 69 |
# File 'lib/kstor/crypto/armored_value.rb', line 67 def [](key) to_hash[key] end |
#[]=(key, val) ⇒ Object
Set value for a key.
75 76 77 78 79 |
# File 'lib/kstor/crypto/armored_value.rb', line 75 def []=(key, val) h = to_hash h[key] = val @value = ASCIIArmor.encode(h.to_json) end |
#to_hash ⇒ Hash
Convert to Ruby Hash.
59 60 61 |
# File 'lib/kstor/crypto/armored_value.rb', line 59 def to_hash JSON.parse(to_binary) end |