class BConfig
configuration
Constants
- HOME
- VALID
- YAMLCONF
Public Class Methods
new()
click to toggle source
# File lib/config.rb, line 59 def initialize # config defaults (for osx, default chrome profile) readyaml = read(YAMLCONF) default_config = { :browser => 'open ', :searcher => "https://google.com/search?q=", :bookmarks => HOME + "/Library/Application Support/Google/Chrome/Profile 1/Bookmarks", } # configure w/ yaml config file, if it exists @config = readyaml ? readyaml : default_config # prune bad config keys @config.each do |k, v| if !VALID.include? k.to_sym puts "Failure:".red + " Bad key found in config file: #{k}" exit 1 end end end
Public Instance Methods
bookmarks()
click to toggle source
# File lib/config.rb, line 107 def bookmarks @config[:bookmarks] end
read(file)
click to toggle source
# File lib/config.rb, line 81 def read(file) begin config = YAML::load(IO.read(file)) rescue Errno::ENOENT puts "Warning: ".yel + "YAML configuration file couldn't be found. Using defaults." puts "Suggest: ".grn + "booker --install config" return false rescue Psych::SyntaxError puts "Warning: ".red + "YAML configuration file contains invalid syntax. Using defaults." return false end config end
searcher()
click to toggle source
# File lib/config.rb, line 111 def searcher @config[:searcher] end
write(k=nil, v=nil)
click to toggle source
used for creating and updating the default configuration
# File lib/config.rb, line 98 def write(k=nil, v=nil) if k.nil? && v.nil? File.open(YAMLCONF, 'w') {|f| f.write(@config.to_yaml) } else @config[k] = v # update users yaml config file File.open(YAMLCONF, 'w+') {|f| f.write(@config.to_yaml) } end end