Class: SweetStaging::LogFile

Inherits:
Object
  • Object
show all
Defined in:
lib/sweet_staging.rb

Overview

%i(debug info warn error fatal unknown).each do |method_name|

  define_method(method_name) { |*_args| }
end

end

Constant Summary collapse

MAX_LINES =
1000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, client_total_lines:) ⇒ LogFile

Returns a new instance of LogFile.



59
60
61
62
# File 'lib/sweet_staging.rb', line 59

def initialize(path:, client_total_lines:)
  @path               = path
  @client_total_lines = client_total_lines.presence || MAX_LINES
end

Instance Attribute Details

#client_total_linesObject (readonly)

Returns the value of attribute client_total_lines.



57
58
59
# File 'lib/sweet_staging.rb', line 57

def client_total_lines
  @client_total_lines
end

#pathObject (readonly)

Returns the value of attribute path.



57
58
59
# File 'lib/sweet_staging.rb', line 57

def path
  @path
end

Instance Method Details

#amountObject



76
77
78
79
80
81
# File 'lib/sweet_staging.rb', line 76

def amount
  result = total_lines - client_total_lines.to_i
  result = MAX_LINES if result < 0
  result = MAX_LINES if result > MAX_LINES
  result
end

#readlinesObject



71
72
73
74
# File 'lib/sweet_staging.rb', line 71

def readlines
  #puts "tail -n #{amount} #{path}"
  `tail -n #{amount} #{path}`.split(/\n/)
end

#total_linesObject



64
65
66
67
68
69
# File 'lib/sweet_staging.rb', line 64

def total_lines
  @total_lines ||= begin
    #puts "wc -l #{path}"
    `wc -l #{path}`.split.first.to_i
  end
end