Sha256: 3a4b85b01da368ce331468d06ece734d8eccd091b044ca8cd5a2e08394a2d9a2
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
require 'fileutils' require 'yaml' module Quandl module Command class QConfig class << self def configuration @configuration ||= self.new( config_file: config_file ) end 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 def config_file convert_legacy_config @config_file ||= File.join(root_path, 'config') end def root_path @root_path ||= File.join(ENV['HOME'], '.quandl') end protected def define_attributes(*attr_names) attr_names.each do |attr_name| define_attribute(attr_name) end end def define_attribute(name) define_method(name){ read_attribute(name) } define_method("#{name}="){|v| write_attribute(name, v) } end end attr_accessor :options define_attributes :token, :quandl_url, :last_checked_for_update def initialize(*args) self.options = OpenStruct.new(args.extract_options!) end def config @config ||= OpenStruct.new(YAML.load(File.read(options.config_file))) end private def read_attribute(name) config.send(name) end def write_attribute(name, value) config.send("#{name}=", value) commit_config end def commit_config File.write( options.config_file, YAML.dump(config.marshal_dump) ) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
quandl-0.2.22 | lib/quandl/command/qconfig.rb |