lib/rack/logs/viewer.rb in rack-logs-0.0.1 vs lib/rack/logs/viewer.rb in rack-logs-0.0.2

- old
+ new

@@ -6,24 +6,37 @@ @config = config end attr_reader :config def call env - [200, headers, [joined_logs]] + [200, headers, joined_logs] end private def headers { 'Content-Type' => 'text/plain' } end - def joined_logs - logs.inject("") do |string, (filename, contents)| - string + "## " + filename + "\n\n" + contents + class JoinedFiles + def initialize filenames + @filenames = filenames end + + def each &block + @filenames.each do |filename| + block.call "## #{filename}\n\n" + ::File.open(filename) do |file| + file.each(&block) + end + end + end + end + + def joined_logs + JoinedFiles.new files end def logs files.inject({}) do |hash, filename| hash[filename] = ::File.read(filename)