config: Make code more readable.

This commit is contained in:
Glenn Y. Rolland 2014-10-29 23:46:02 +01:00
parent 3e29c275b8
commit eabc2c8dcf

View file

@ -4,7 +4,6 @@ require 'ostruct'
require 'pp' require 'pp'
require 'find' require 'find'
#require 'rdebug/base'
require 'qasim' require 'qasim'
module Qasim module Qasim
@ -15,8 +14,6 @@ module Qasim
attr_reader :mnt_dir attr_reader :mnt_dir
def initialize def initialize
@mnt_dir = File.join ENV['HOME'], "mnt" @mnt_dir = File.join ENV['HOME'], "mnt"
@config_dir = APP_CONFIG_DIR @config_dir = APP_CONFIG_DIR
@ -30,27 +27,26 @@ module Qasim
end end
def parse_maps &blk def parse_maps &blk
#rdebug "Config: #{@config_dir}/config"
@maps = [] @maps = []
map_dirs = [@config_dir, APP_SYSCONFIG_DIR].select{ |d| map_dirs = [@config_dir, APP_SYSCONFIG_DIR].select{ |d|
File.exist? d and File.directory? d File.exist? d and File.directory? d
} }
Find.find( *map_dirs ) do |path| Find.find( *map_dirs ) do |path|
if File.file? path # Skip unwanted files fast
if File.basename( path ) =~ /.map$/ next unless File.file? path
begin next unless File.basename( path ) =~ /.map$/
map = Map.new self, path
yield map if block_given? begin
maps.push map map = Map.new self, path
rescue yield map if block_given?
# error while parsing map maps.push map
end rescue
end raise RuntimeError, "Error while parsing map file"
#total_size += FileTest.size(path)
end end
end end
end end
end end
end end