Class: Kubetailrb::Reader::FileReader

Inherits:
Object
  • Object
show all
Includes:
Validated
Defined in:
lib/kubetailrb/reader/file_reader.rb

Overview

Read file content

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validated

#raise_if_blank, #raise_if_nil, #validate_boolean, #validate_last_nb_lines

Constructor Details

#initialize(filepath:, last_nb_lines:, follow:) ⇒ FileReader

Returns a new instance of FileReader.



13
14
15
16
17
18
19
# File 'lib/kubetailrb/reader/file_reader.rb', line 13

def initialize(filepath:, last_nb_lines:, follow:)
  @filepath = filepath
  @last_nb_lines = last_nb_lines
  @follow = follow

  validate
end

Instance Attribute Details

#filepathObject (readonly)

Returns the value of attribute filepath.



11
12
13
# File 'lib/kubetailrb/reader/file_reader.rb', line 11

def filepath
  @filepath
end

#last_nb_linesObject (readonly)

Returns the value of attribute last_nb_lines.



11
12
13
# File 'lib/kubetailrb/reader/file_reader.rb', line 11

def last_nb_lines
  @last_nb_lines
end

Instance Method Details

#follow?Boolean

NOTE: Is there something like ‘attr_reader` but for boolean? Nope, Ruby does not know if a variable is a boolean or not. So it cannot create a dedicated method for those booleans.

Returns:



29
30
31
# File 'lib/kubetailrb/reader/file_reader.rb', line 29

def follow?
  @follow
end

#readObject



21
22
23
24
# File 'lib/kubetailrb/reader/file_reader.rb', line 21

def read
  # naive_read
  read_with_fd
end