Class: Rack::Logs::Viewer::JoinedFiles
- Inherits:
-
Object
- Object
- Rack::Logs::Viewer::JoinedFiles
- Includes:
- Enumerable
- Defined in:
- lib/rack/logs/viewer.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(filenames, lines) ⇒ JoinedFiles
constructor
A new instance of JoinedFiles.
Constructor Details
#initialize(filenames, lines) ⇒ JoinedFiles
Returns a new instance of JoinedFiles.
30 31 32 33 |
# File 'lib/rack/logs/viewer.rb', line 30 def initialize filenames, lines @filenames = filenames @lines = lines end |
Instance Method Details
#each(&block) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rack/logs/viewer.rb', line 39 def each &block @filenames.each do |filename| block.call "## #{filename}\n\n" ::File.open(filename) do |file| total = 0 file.each_line { total += 1 } progress = 0 file.rewind file.each_line do |line| if progress > (total - @lines) block.call line end progress += 1 end end end end |
#empty? ⇒ Boolean
35 36 37 |
# File 'lib/rack/logs/viewer.rb', line 35 def empty? @filenames.empty? end |