class RailsLogParser::NotParseableLines

Attributes

lines[R]

Public Class Methods

new() click to toggle source
# File lib/rails_log_parser/not_parseable_lines.rb, line 8
def initialize
  @lines = []
  @path = File.join(File.dirname(RailsLogParser::Parser.log_path), 'not_parseable_lines.json')
  load_file
end

Public Instance Methods

push(line) click to toggle source
# File lib/rails_log_parser/not_parseable_lines.rb, line 14
def push(line)
  @lines.push(line) unless today_lines.include?(line)
end
save() click to toggle source
# File lib/rails_log_parser/not_parseable_lines.rb, line 18
def save
  @stats[Date.today.to_s] = today_lines + lines

  last_7_days = (0..6).map { |i| (Date.today - i) }.map(&:to_s)
  @stats.each_key do |key|
    @stats.delete(key) unless last_7_days.include?(key)
  end
  File.write(@path, @stats.to_json)
end

Protected Instance Methods

load_file() click to toggle source
# File lib/rails_log_parser/not_parseable_lines.rb, line 34
def load_file
  @stats = JSON.parse(File.read(@path))
  @stats ||= {}
rescue JSON::ParserError, Errno::ENOENT
  @stats = {}
end
today_lines() click to toggle source
# File lib/rails_log_parser/not_parseable_lines.rb, line 30
def today_lines
  @stats[Date.today.to_s] || []
end