Sha256: 55d96756d6582b3272e39abf1d0e32f85b3eca6efb490b121b297346c4fc98f3
Contents?: true
Size: 1.15 KB
Versions: 7
Compression:
Stored size: 1.15 KB
Contents
module Munge class System module Readers # Enumerable list of {Munge::Item}s class Filesystem include Enumerable # @param source_path [String] def initialize(source_path) @source_path = source_path end # @yield [Item] # @return [Enumerator] def each return enum_for(:each) unless block_given? filepaths = Dir.glob(File.join(@source_path, "**", "*")) .select { |path| File.file?(path) } filepaths.each do |abspath| filehash = Hash[ relpath: compute_relpath(abspath), content: compute_content(abspath), stat: compute_stat(abspath) ] yield filehash end end private def compute_stat(abspath) File.stat(abspath) end def compute_relpath(abspath) folder = Pathname.new(@source_path) file = Pathname.new(abspath) file.relative_path_from(folder).to_s end def compute_content(abspath) File.read(abspath) end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems