Class: RubyCoded::Auth::CredentialsStore

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_coded/auth/credentials_store.rb

Overview

This class is used to manage the credentials in the config file

Instance Method Summary collapse

Constructor Details

#initialize(config_path: UserConfig::CONFIG_PATH) ⇒ CredentialsStore

Returns a new instance of CredentialsStore.



11
12
13
# File 'lib/ruby_coded/auth/credentials_store.rb', line 11

def initialize(config_path: UserConfig::CONFIG_PATH)
  @config = UserConfig.new(config_path: config_path)
end

Instance Method Details

#remove(provider_name) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/ruby_coded/auth/credentials_store.rb', line 26

def remove(provider_name)
  providers = @config.full_config["providers"]
  return unless providers

  providers.delete(provider_name.to_s)
  @config.save
end

#retrieve(provider_name) ⇒ Object



22
23
24
# File 'lib/ruby_coded/auth/credentials_store.rb', line 22

def retrieve(provider_name)
  @config.full_config.dig("providers", provider_name.to_s)
end

#store(provider_name, credentials) ⇒ Object



15
16
17
18
19
20
# File 'lib/ruby_coded/auth/credentials_store.rb', line 15

def store(provider_name, credentials)
  cfg = @config.full_config
  cfg["providers"] ||= {}
  cfg["providers"][provider_name.to_s] = credentials
  @config.save
end