module GLSAgent::Dotfile
Public Class Methods
get_opts()
click to toggle source
Get keys and values from file in ~/.gls_agent and put them in a hash. keys are symbols. The file should follow the syntax
option=value option2=value2
Meaningful keys are i.e. user and pass.
# File lib/gls_agent/dotfile.rb, line 9 def self.get_opts options = {} # Get defaults from ~/.gls_agent begin filecontent = File.open("#{Dir.home}/.gls_agent").read options = hash_from_text filecontent puts "Info: read configuration parameters from ~/.gls_agent, may be overriden with cmd line options." rescue STDERR.puts "Info: No configuration file in ~/.gls_agent found, all options need to be specified on command line." #STDERR.puts $!.inspect,$@ end options end
hash_from_text(text)
click to toggle source
# File lib/gls_agent/dotfile.rb, line 23 def self.hash_from_text text hash = {} text.each_line do |line| fields = line.split('=') fields.each &:strip! fields.each &:rstrip! hash[fields[0].to_sym] = fields[1] end hash end