Sha256: 3d2e3faead82a6fe92f702069aac265b1afdad945c7d0769ac7ce9d5231bde70

Contents?: true

Size: 930 Bytes

Versions: 2

Compression:

Stored size: 930 Bytes

Contents

# frozen_string_literal: true
require 'as_deprecation_tracker/whitelist_entry'
require 'rails/backtrace_cleaner'

module ASDeprecationTracker
  # Rewrites the whitelist configuration file to append new observed entries
  class Writer
    def initialize(filename)
      @filename = filename
      @contents = []
      @contents = YAML.load(File.read(filename)) || [] if File.exist?(filename)
    end

    def add(message, callstack)
      cleanup_match = WhitelistEntry::MESSAGE_CLEANUP_RE.match(message)
      message = cleanup_match[1] if cleanup_match

      callstack = Rails::BacktraceCleaner.new.clean(callstack, :silent)

      entry = { 'message' => message, 'callstack' => callstack.first }
      @contents << entry
      entry
    end

    def contents
      @contents.sort_by { |e| e.values_at('message', 'callstack').compact }.to_yaml
    end

    def write_file
      File.write(@filename, contents)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
as_deprecation_tracker-1.5.0 lib/as_deprecation_tracker/writer.rb
as_deprecation_tracker-1.4.1 lib/as_deprecation_tracker/writer.rb