lib/etcdist/reader.rb in etcdist-0.0.5 vs lib/etcdist/reader.rb in etcdist-0.0.6
- old
+ new
@@ -14,17 +14,23 @@
files = Dir[File.join(@dir, '**', '*')].reject { |p| File.directory? p }
Log.info("found #{files.length} files in #{@dir}")
files.reduce(Hash.new { |h, k| h[k] = {} }) do |h, f|
directory = File.dirname(f).gsub(@dir, '')
- entries = Hash[IO.readlines(f).map { |e| e.chomp.split('=', 2) }.select { |k, _| valid_key?(k) }]
+ entries = Hash[read_non_blank_lines(f).map { |e| e.chomp.split('=', 2) }.select { |k, _| valid_key?(k) }]
Log.debug("found #{entries.length} entries in #{f.gsub(@dir, '')}: #{entries}")
h[directory].merge!(entries)
h
end
end
private
+
+ def read_non_blank_lines(f)
+ lines = IO.readlines(f)
+ lines.delete_if { |line| line !~ /\S/ }
+ lines
+ end
def valid_key?(key)
is_valid = !(key.include? '/')
Log.warn("ignoring invalid key #{key}") unless is_valid
is_valid