Class: Mellon::Store
- Inherits:
-
Object
- Object
- Mellon::Store
- Defined in:
- lib/mellon/store.rb
Overview
Used for storing multiple values in a single Keychain entry.
This is useful for configuring applications, e.g. having one entry per application, where each entry contains all configuration for said application.
Instance Attribute Summary collapse
-
#keychain ⇒ Object
readonly
Returns the value of attribute keychain.
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
-
#serializer ⇒ Object
readonly
Returns the value of attribute serializer.
Instance Method Summary collapse
-
#[](key) ⇒ String?
Retrieve a key from the store.
-
#[]=(key, value) ⇒ Object
Set a key in the store.
- #fetch(*args, &block) ⇒ Object
-
#initialize(project_name, keychain: Keychain.search(project_name), serializer: YAML) ⇒ Store
constructor
A new instance of Store.
- #to_h ⇒ Hash
Constructor Details
#initialize(project_name) ⇒ Store #initialize(project_name, keychain_name) ⇒ Store #initialize(project_name, keychain) ⇒ Store
Returns a new instance of Store.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mellon/store.rb', line 29 def initialize(project_name, keychain: Keychain.search(project_name), serializer: YAML) @project_name = project_name.to_s @keychain = if keychain.is_a?(Keychain) keychain elsif keychain.nil? Keychain.default else Keychain.find(keychain.to_s) end @serializer = serializer end |
Instance Attribute Details
#keychain ⇒ Object (readonly)
Returns the value of attribute keychain.
10 11 12 |
# File 'lib/mellon/store.rb', line 10 def keychain @keychain end |
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
9 10 11 |
# File 'lib/mellon/store.rb', line 9 def project_name @project_name end |
#serializer ⇒ Object (readonly)
Returns the value of attribute serializer.
11 12 13 |
# File 'lib/mellon/store.rb', line 11 def serializer @serializer end |
Instance Method Details
#[](key) ⇒ String?
Retrieve a key from the store.
50 51 52 |
# File 'lib/mellon/store.rb', line 50 def [](key) data[key] end |
#[]=(key, value) ⇒ Object
Set a key in the store.
58 59 60 |
# File 'lib/mellon/store.rb', line 58 def []=(key, value) dump data.merge(key => value) end |
#fetch(*args, &block) ⇒ Object
42 43 44 |
# File 'lib/mellon/store.rb', line 42 def fetch(*args, &block) data.fetch(*args, &block) end |
#to_h ⇒ Hash
63 64 65 |
# File 'lib/mellon/store.rb', line 63 def to_h data end |