Class: ASDeprecationTracker::Writer

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

Overview

Rewrites the whitelist configuration file to append new observed entries

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Writer

Returns a new instance of Writer.



9
10
11
12
13
# File 'lib/as_deprecation_tracker/writer.rb', line 9

def initialize(filename)
  @filename = filename
  @contents = []
  @contents = YAML.load(File.read(filename)) || [] if File.exist?(filename)
end

Instance Method Details

#add(message, callstack) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/as_deprecation_tracker/writer.rb', line 15

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

#contentsObject



26
27
28
# File 'lib/as_deprecation_tracker/writer.rb', line 26

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

#write_fileObject



30
31
32
# File 'lib/as_deprecation_tracker/writer.rb', line 30

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