Sha256: 33d1af87feeb0b19817055b9521ddd14d197d644dfdc51425fad67e2a1ee29b6
Contents?: true
Size: 1.25 KB
Versions: 2
Compression:
Stored size: 1.25 KB
Contents
module Tw class Conf def self.default { 'version' => Tw::VERSION, 'consumer_key' => 'AYhhkOC8H2yTZyelz3uw', 'consumer_secret' => '28Ba8YyFDSPgoCYAmH5ANqOmT6qVS8gIhKnUiDbIpU', 'default_user' => nil, 'users' => {} } end def self.[](key) ENV[key] || conf[key] end def self.[]=(key,value) conf[key] = value end def self.conf_file "#{ENV['HOME']}/.tw.yml" end def self.conf @@conf ||= ( res = default if File.exists? conf_file begin open_conf_file do |f| res = YAML::load f.read end rescue => e STDERR.puts e File.delete conf_file end end res ) end def self.to_yaml self.conf.to_yaml end def self.save open_conf_file('w+') do |f| f.write conf.to_yaml end end private def self.open_conf_file(opt=nil, &block) if block_given? yield open(self.conf_file, opt) else return open(self.conf_file, opt) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tw-0.0.3 | lib/tw/conf.rb |
tw-0.0.2 | lib/tw/conf.rb |