lib/etcdist/reader.rb in etcdist-0.0.6 vs lib/etcdist/reader.rb in etcdist-0.0.7

- old
+ new

@@ -1,6 +1,7 @@ require 'etcdist/log' +require 'pathname' module Etcdist # Reads data from file system into directories, keys and values. class Reader # @param [String] dir The path to the data directory @@ -19,9 +20,20 @@ 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 + + def all_dirs + @dir = Pathname.new File.expand_path(@dir) + root = Pathname.new '/' + + descendant_dirs = Dir[File.join(@dir, '**', '*')].select { |p| File.directory? p } + relative_descendant_dirs = descendant_dirs.map { |d| Pathname.new(d).relative_path_from @dir } + dirs = relative_descendant_dirs.map { |d| root.join(d).to_s } + + dirs.push '/' end private def read_non_blank_lines(f)