Class: IGMarkets::CLI::ConfigFile

Inherits:
Object
  • Object
show all
Defined in:
lib/ig_markets/cli/config_file.rb

Overview

Helper class for working with the config files supported by the command-line client.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ ConfigFile

Initializes this config file with the contents of the specified config file.



6
7
8
# File 'lib/ig_markets/cli/config_file.rb', line 6

def initialize(config_file)
  @lines = File.readlines config_file
end

Class Method Details

.findCLI::ConfigFile

Returns the config file to use, or nil if there is no config file.

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ig_markets/cli/config_file.rb', line 23

def self.find
  config_file_locations = [
    "#{Dir.pwd}/.ig_markets",
    "#{Dir.home}/.ig_markets"
  ]

  config_file = config_file_locations.detect do |filename|
    File.exist? filename
  end

  config_file ? new(config_file) : nil
end

Instance Method Details

#argumentsArray<String>

Returns the arguments in this config file as an array.

Returns:

  • (Array<String>)


13
14
15
16
17
18
# File 'lib/ig_markets/cli/config_file.rb', line 13

def arguments
  @lines.map { |line| line.gsub(/#.*/, '') }
        .map(&:strip)
        .join(' ')
        .split(' ')
end