Class: IGMarkets::CLI::ConfigFile
- Inherits:
-
Object
- Object
- IGMarkets::CLI::ConfigFile
- 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
-
.find ⇒ CLI::ConfigFile
Returns the config file to use, or nil if there is no config file.
Instance Method Summary collapse
-
#arguments ⇒ Array<String>
Returns the arguments in this config file as an array.
-
#initialize(config_file) ⇒ ConfigFile
constructor
Initializes this config file with the contents of the specified config file.
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
.find ⇒ CLI::ConfigFile
Returns the config file to use, or nil if there is no config file.
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
#arguments ⇒ Array<String>
Returns the arguments in this config file as an array.
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 |