class Twitterpunch::Configuration
Public Class Methods
new(file)
click to toggle source
# File lib/twitterpunch/configuration.rb, line 8 def initialize(file) @configfile = file @config = YAML.load_file(@configfile) rescue defaults end
Public Instance Methods
configure()
click to toggle source
# File lib/twitterpunch/configuration.rb, line 47 def configure puts "Existing Twitter authorization will not be altered." if @config.include? :twitter print "Would you like to save default configuration values [y/N]? " return unless STDIN.gets.strip.downcase == 'y' @config.merge! defaults # This is not in defaults so it doesn't take precedence @config[:twitter] ||= {} @config[:twitter][:consumer_key] ||= Twitterpunch::API_KEY @config[:twitter][:consumer_secret] ||= Twitterpunch::API_SECRET puts "Please edit #{@configfile} to configure." puts 'If you have your own Twitter consumer key/secret, you may replace' puts 'the defaults before running `twitterpunch --authorize`.' end
defaults()
click to toggle source
# File lib/twitterpunch/configuration.rb, line 71 def defaults puts "Generating default configuration options..." { :messages => [ "Hello there", "I'm a posting fool", "minimally viable product" ], :viewer => { :count => 5, }, :hashtag => "Twitterpunch", :photodir => "~/Pictures/twitterpunch/", :logfile => '~/.twitterpunch/activity.log', } end
save()
click to toggle source
# File lib/twitterpunch/configuration.rb, line 63 def save puts @config.to_yaml puts print "Save configuration [y/N]? " return unless STDIN.gets.strip.downcase == 'y' File.open(@configfile, 'w') {|f| f.write(@config.to_yaml) } end