Class: Tastytrade::CLIConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/tastytrade/cli_config.rb

Overview

Configuration management for Tastytrade CLI

Constant Summary collapse

CONFIG_DIR =
File.expand_path("~/.config/tastytrade")
CONFIG_FILE =
File.join(CONFIG_DIR, "config.yml")
DEFAULT_CONFIG =
{
  "default_account" => nil,
  "environment" => "production",
  "auto_refresh" => true
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLIConfig

Returns a new instance of CLIConfig.



20
21
22
# File 'lib/tastytrade/cli_config.rb', line 20

def initialize
  @data = load_config
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



18
19
20
# File 'lib/tastytrade/cli_config.rb', line 18

def data
  @data
end

Instance Method Details

#delete(key) ⇒ Object

Delete a configuration value



36
37
38
39
# File 'lib/tastytrade/cli_config.rb', line 36

def delete(key)
  @data.delete(key.to_s)
  save_config
end

#exists?Boolean

Check if config exists

Returns:

  • (Boolean)


42
43
44
# File 'lib/tastytrade/cli_config.rb', line 42

def exists?
  File.exist?(CONFIG_FILE)
end

#get(key) ⇒ Object

Get a configuration value



25
26
27
# File 'lib/tastytrade/cli_config.rb', line 25

def get(key)
  @data[key.to_s]
end

#reset!Object

Reset to defaults



47
48
49
50
# File 'lib/tastytrade/cli_config.rb', line 47

def reset!
  @data = DEFAULT_CONFIG.dup
  save_config
end

#set(key, value) ⇒ Object

Set a configuration value



30
31
32
33
# File 'lib/tastytrade/cli_config.rb', line 30

def set(key, value)
  @data[key.to_s] = value
  save_config
end