Class: KBSecret::Config

Inherits:
Object
  • Object
show all
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.expand_path("~/.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: "kbsecret",
    }
  }
}.freeze
@@config =
DEFAULT_CONFIG.merge(user_config)

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object

Retrieve a configured value.

Parameters:

  • key (String)

Returns:

  • (Object)

    the corresponding configuration



31
32
33
# File 'lib/kbsecret/config.rb', line 31

def self.[](key)
  @@config[key]
end

.configure_session(label, hsh) ⇒ Object

Configure a session.

Parameters:

  • label (Symbol)

    the session label

  • hsh (Hash)

    the session configuration



56
57
58
59
# File 'lib/kbsecret/config.rb', line 56

def self.configure_session(label, hsh)
  @@config[:sessions][label.to_sym] = hsh
  File.open(CONFIG_FILE, "w") { |io| io.write @@config.to_yaml }
end

.session(sess) ⇒ Hash

Retrieve a session's configuration.

Parameters:

  • sess (Symbol)

    the session's label

Returns:

  • (Hash)

    the session configuration



38
39
40
# File 'lib/kbsecret/config.rb', line 38

def self.session(sess)
  @@config[:sessions][sess]
end

.session?(sess) ⇒ Boolean

Returns whether or not the given session is configured.

Parameters:

  • sess (Symbol)

    the session label

Returns:

  • (Boolean)

    whether or not the given session is configured



49
50
51
# File 'lib/kbsecret/config.rb', line 49

def self.session?(sess)
  session_labels.include?(sess.to_sym)
end

.session_labelsArray<Symbol>

Returns all configured session labels.

Returns:

  • (Array<Symbol>)

    all configured session labels



43
44
45
# File 'lib/kbsecret/config.rb', line 43

def self.session_labels
  @@config[:sessions].keys
end