Class: SchwabRb::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/schwab_rb/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/schwab_rb/configuration.rb', line 8

def initialize
  @logger = nil
  @log_file = ENV.fetch("SCHWAB_LOGFILE", nil)
  @log_level = ENV.fetch("SCHWAB_LOG_LEVEL", "WARN").upcase
  @silence_output = ENV.fetch("SCHWAB_SILENCE_OUTPUT", "false").downcase == "true"

  default_home = File.expand_path("~/.schwab_rb")
  @schwab_home = ENV.fetch("SCHWAB_HOME", default_home)
  @account_hashes_path = ENV.fetch("SCHWAB_ACCOUNT_HASHES_PATH", File.join(@schwab_home, "account_hashes.json"))
  @account_names_path = ENV.fetch("SCHWAB_ACCOUNT_NAMES_PATH", File.join(@schwab_home, "account_names.json"))
end

Instance Attribute Details

#account_hashes_pathObject

Returns the value of attribute account_hashes_path.



5
6
7
# File 'lib/schwab_rb/configuration.rb', line 5

def 
  @account_hashes_path
end

#account_names_pathObject

Returns the value of attribute account_names_path.



5
6
7
# File 'lib/schwab_rb/configuration.rb', line 5

def 
  @account_names_path
end

#log_fileObject

Returns the value of attribute log_file.



5
6
7
# File 'lib/schwab_rb/configuration.rb', line 5

def log_file
  @log_file
end

#log_levelObject

Returns the value of attribute log_level.



5
6
7
# File 'lib/schwab_rb/configuration.rb', line 5

def log_level
  @log_level
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/schwab_rb/configuration.rb', line 5

def logger
  @logger
end

#schwab_homeObject

Returns the value of attribute schwab_home.



5
6
7
# File 'lib/schwab_rb/configuration.rb', line 5

def schwab_home
  @schwab_home
end

#silence_outputObject

Returns the value of attribute silence_output.



5
6
7
# File 'lib/schwab_rb/configuration.rb', line 5

def silence_output
  @silence_output
end

Instance Method Details

#effective_log_fileObject



28
29
30
# File 'lib/schwab_rb/configuration.rb', line 28

def effective_log_file
  @log_file || (ENV["LOGFILE"] if ENV["LOGFILE"] && !ENV["LOGFILE"].empty?)
end

#has_external_logger?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/schwab_rb/configuration.rb', line 20

def has_external_logger?
  !@logger.nil?
end

#should_create_logger?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/schwab_rb/configuration.rb', line 24

def should_create_logger?
  !has_external_logger? && !@silence_output
end