Class: Quandl::Command::QConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/quandl/command/qconfig.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ QConfig

Returns a new instance of QConfig.



51
52
53
# File 'lib/quandl/command/qconfig.rb', line 51

def initialize(*args)
  self.options = OpenStruct.new(args.extract_options!)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



47
48
49
# File 'lib/quandl/command/qconfig.rb', line 47

def options
  @options
end

Class Method Details

.config_fileObject



23
24
25
26
# File 'lib/quandl/command/qconfig.rb', line 23

def config_file
  convert_legacy_config
  @config_file ||= File.join(root_path, 'config')
end

.configurationObject



10
11
12
# File 'lib/quandl/command/qconfig.rb', line 10

def configuration
  @configuration ||= self.new( config_file: config_file )
end

.convert_legacy_configObject



14
15
16
17
18
19
20
21
# File 'lib/quandl/command/qconfig.rb', line 14

def convert_legacy_config
  return if File.directory?(root_path)
  # otherwise move the old .quandl into .quandl/config
  FileUtils.mv(root_path, "#{root_path}.old")
  FileUtils.mkdir(root_path)
  token = File.read("#{root_path}.old")
  File.write(config_file, "token: #{token}")
end

.root_pathObject



28
29
30
# File 'lib/quandl/command/qconfig.rb', line 28

def root_path
  @root_path ||= File.join(ENV['HOME'], '.quandl')
end

Instance Method Details

#configObject



55
56
57
# File 'lib/quandl/command/qconfig.rb', line 55

def config
  @config ||= OpenStruct.new(YAML.load(File.read(options.config_file)))
end