Class: SecureConf::Config
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- SecureConf::Config
- Defined in:
- lib/secure_conf/config.rb
Instance Attribute Summary collapse
-
#auto_commit ⇒ Object
Returns the value of attribute auto_commit.
-
#encrypter ⇒ Object
readonly
Returns the value of attribute encrypter.
-
#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
-
#delete(key) ⇒ Object
delete.
-
#initialize(path, encrypter: nil, serializer: nil, storage: nil, auto_commit: false) ⇒ Config
constructor
A new instance of Config.
-
#plain_get(key) ⇒ Object
get.
-
#plain_store(key, value) ⇒ Object
store.
-
#save ⇒ Object
save.
- #secure_store(key, value) ⇒ Object
- #store(key, value) ⇒ Object (also: #[]=)
Constructor Details
#initialize(path, encrypter: nil, serializer: nil, storage: nil, auto_commit: false) ⇒ Config
Returns a new instance of Config.
11 12 13 14 15 16 17 18 |
# File 'lib/secure_conf/config.rb', line 11 def initialize(path, encrypter: nil, serializer: nil, storage: nil, auto_commit: false) @path = path @encrypter = encrypter || SecureConf.default @serializer = serializer || Serializer::Marshal @storage = storage || Storage.fetch(path) @auto_commit = auto_commit super(@storage.load(path)) end |
Instance Attribute Details
#auto_commit ⇒ Object
Returns the value of attribute auto_commit.
9 10 11 |
# File 'lib/secure_conf/config.rb', line 9 def auto_commit @auto_commit end |
#encrypter ⇒ Object (readonly)
Returns the value of attribute encrypter.
6 7 8 |
# File 'lib/secure_conf/config.rb', line 6 def encrypter @encrypter end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/secure_conf/config.rb', line 5 def path @path end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
7 8 9 |
# File 'lib/secure_conf/config.rb', line 7 def serializer @serializer end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
8 9 10 |
# File 'lib/secure_conf/config.rb', line 8 def storage @storage end |
Instance Method Details
#[](key) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/secure_conf/config.rb', line 47 def [](key) value = plain_get(key) if value && key.to_s.start_with?("enc:") value = @encrypter.decrypt(value) value = @serializer.load(value) end value end |
#delete(key) ⇒ Object
delete
58 59 60 61 |
# File 'lib/secure_conf/config.rb', line 58 def delete(key) __getobj__.delete(key) save if @auto_commit end |
#plain_get(key) ⇒ Object
get
43 44 45 |
# File 'lib/secure_conf/config.rb', line 43 def plain_get(key) __getobj__[key] end |
#plain_store(key, value) ⇒ Object
store
22 23 24 25 |
# File 'lib/secure_conf/config.rb', line 22 def plain_store(key, value) __getobj__.store(key, value) save if @auto_commit end |
#save ⇒ Object
save
65 66 67 |
# File 'lib/secure_conf/config.rb', line 65 def save @storage.save(path, __getobj__) end |
#secure_store(key, value) ⇒ Object
27 28 29 30 |
# File 'lib/secure_conf/config.rb', line 27 def secure_store(key, value) value = @serializer.dump(value) plain_store(key, @encrypter.encrypt(value)) end |
#store(key, value) ⇒ Object Also known as: []=
32 33 34 35 36 37 38 |
# File 'lib/secure_conf/config.rb', line 32 def store(key, value) if key.to_s.start_with?("enc:") secure_store(key, value) else plain_store(key, value) end end |