Class: KBSecret::Config
- Inherits:
-
Object
- Object
- KBSecret::Config
- Defined in:
- lib/kbsecret/config.rb
Overview
Global and per-session configuration for kbsecret.
Constant Summary collapse
- CONFIG_DIR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
the configuration directory
File.("~/.config/kbsecret").freeze
- CONFIG_FILE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
the configuration file
File.join(CONFIG_DIR, "config.yml").freeze
- DEFAULT_CONFIG =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
configuration defaults
{ mount: "/keybase", sessions: { default: { users: [Keybase.current_user], root: "default", }, }, session_root: File.join("/keybase/private/", Keybase.current_user, "kbsecret"), }.freeze
Class Method Summary collapse
-
.[](key) ⇒ Object
Retrieve a configured value.
-
.configure_session(label, hsh) ⇒ void
Configure a session.
-
.deconfigure_session(label) ⇒ void
Deconfigure a session.
-
.session(sess) ⇒ Hash
Retrieve a session's configuration.
-
.session?(sess) ⇒ Boolean
Whether or not the given session is configured.
-
.session_labels ⇒ Array<Symbol>
All configured session labels.
Class Method Details
.[](key) ⇒ Object
Retrieve a configured value.
36 37 38 |
# File 'lib/kbsecret/config.rb', line 36 def self.[](key) @config[key] end |
.configure_session(label, hsh) ⇒ void
This method returns an undefined value.
Configure a session.
62 63 64 65 |
# File 'lib/kbsecret/config.rb', line 62 def self.configure_session(label, hsh) @config[:sessions][label.to_sym] = hsh File.open(CONFIG_FILE, "w") { |io| io.write @config.to_yaml } end |
.deconfigure_session(label) ⇒ void
This only removes the given session from the configuration, making
it "invisible" to kbsecret
. To actually remove all files associated
with a session, see Session#unlink!.
This method returns an undefined value.
Deconfigure a session.
73 74 75 76 |
# File 'lib/kbsecret/config.rb', line 73 def self.deconfigure_session(label) @config[:sessions].delete(label.to_sym) File.open(CONFIG_FILE, "w") { |io| io.write @config.to_yaml } end |
.session(sess) ⇒ Hash
Retrieve a session's configuration.
43 44 45 |
# File 'lib/kbsecret/config.rb', line 43 def self.session(sess) @config[:sessions][sess.to_sym] end |
.session?(sess) ⇒ Boolean
Returns whether or not the given session is configured.
54 55 56 |
# File 'lib/kbsecret/config.rb', line 54 def self.session?(sess) session_labels.include?(sess.to_sym) end |
.session_labels ⇒ Array<Symbol>
Returns all configured session labels.
48 49 50 |
# File 'lib/kbsecret/config.rb', line 48 def self.session_labels @config[:sessions].keys end |