Class: Command::Log::Tail

Inherits:
Object
  • Object
show all
Defined in:
lib/command/log/tail.rb

Overview

Constant Summary collapse

CHUNK_SIZE =
1024 * 16

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, num) ⇒ Tail

Returns a new instance of Tail.



15
16
17
18
19
# File 'lib/command/log/tail.rb', line 15

def initialize(path, num)
  self.path = path
  self.num = num
  raise unless num.to_i > 0
end

Instance Attribute Details

#numObject

Returns the value of attribute num.



13
14
15
# File 'lib/command/log/tail.rb', line 13

def num
  @num
end

#pathObject

Returns the value of attribute path.



13
14
15
# File 'lib/command/log/tail.rb', line 13

def path
  @path
end

#stream_ioObject

Returns the value of attribute stream_io.



13
14
15
# File 'lib/command/log/tail.rb', line 13

def stream_io
  @stream_io
end

Instance Method Details

#displayObject



30
31
32
33
34
# File 'lib/command/log/tail.rb', line 30

def display
  execute do |file|
    stream_io.puts file.read
  end
end

#streamObject



21
22
23
24
25
26
27
28
# File 'lib/command/log/tail.rb', line 21

def stream
  execute do |file|
    loop do
      stream_io.print file.read
      sleep 0.1
    end
  end
end