Class: SecureConf::Config
- Inherits:
-
Hash
- Object
- Hash
- SecureConf::Config
- Defined in:
- lib/secure_conf/config.rb
Instance Attribute Summary collapse
-
#auto_commit ⇒ Object
Returns the value of attribute auto_commit.
-
#encripter ⇒ Object
readonly
Returns the value of attribute encripter.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(path, encripter: nil, serializer: nil, storage: nil, auto_commit: false) ⇒ Config
constructor
A new instance of Config.
- #plain_get ⇒ Object
- #plain_store ⇒ Object
- #save ⇒ Object
- #secure_store(key, value) ⇒ Object
- #store(key, value) ⇒ Object (also: #[]=)
Constructor Details
#initialize(path, encripter: nil, serializer: nil, storage: nil, auto_commit: false) ⇒ Config
Returns a new instance of Config.
9 10 11 12 13 14 15 16 |
# File 'lib/secure_conf/config.rb', line 9 def initialize(path, encripter: nil, serializer: nil, storage: nil, auto_commit: false) @path = path @encripter = encripter || SecureConf.default @serializer = serializer || Serializer::Marshal @storage = storage || Storage.fetch(path) @auto_commit = auto_commit self.replace(@storage.load(path)) end |
Instance Attribute Details
#auto_commit ⇒ Object
Returns the value of attribute auto_commit.
7 8 9 |
# File 'lib/secure_conf/config.rb', line 7 def auto_commit @auto_commit end |
#encripter ⇒ Object (readonly)
Returns the value of attribute encripter.
4 5 6 |
# File 'lib/secure_conf/config.rb', line 4 def encripter @encripter end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/secure_conf/config.rb', line 3 def path @path end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
5 6 7 |
# File 'lib/secure_conf/config.rb', line 5 def serializer @serializer end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
6 7 8 |
# File 'lib/secure_conf/config.rb', line 6 def storage @storage end |
Instance Method Details
#[](key) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/secure_conf/config.rb', line 36 def [](key) value = plain_get(key) if value && key.to_s.start_with?("enc:") value = @encripter.decrypt(value) value = @serializer.load(value) end value end |
#plain_get ⇒ Object
34 |
# File 'lib/secure_conf/config.rb', line 34 alias_method :plain_get, :[] |
#plain_store ⇒ Object
18 |
# File 'lib/secure_conf/config.rb', line 18 alias_method :plain_store, :store |
#save ⇒ Object
45 46 47 |
# File 'lib/secure_conf/config.rb', line 45 def save @storage.save(path, self) end |
#secure_store(key, value) ⇒ Object
29 30 31 32 |
# File 'lib/secure_conf/config.rb', line 29 def secure_store(key, value) value = @serializer.dump(value) plain_store(key, @encripter.encrypt(value)) end |
#store(key, value) ⇒ Object Also known as: []=
20 21 22 23 24 25 26 |
# File 'lib/secure_conf/config.rb', line 20 def store(key, value) if key.to_s.start_with?("enc:") secure_store(key, value) else plain_store(key, value) end end |