Class: ASDeprecationTracker::Writer
- Inherits:
-
Object
- Object
- ASDeprecationTracker::Writer
- Defined in:
- lib/as_deprecation_tracker/writer.rb
Overview
Rewrites the whitelist configuration file to append new observed entries
Instance Method Summary collapse
- #add(message, callstack) ⇒ Object
- #contents ⇒ Object
-
#initialize(filename) ⇒ Writer
constructor
A new instance of Writer.
- #write_file ⇒ Object
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(, callstack) cleanup_match = WhitelistEntry::MESSAGE_CLEANUP_RE.match() = cleanup_match[1] if cleanup_match callstack = Rails::BacktraceCleaner.new.clean(callstack, :silent) entry = { 'message' => , 'callstack' => callstack.first } @contents << entry entry end |
#contents ⇒ Object
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_file ⇒ Object
30 31 32 |
# File 'lib/as_deprecation_tracker/writer.rb', line 30 def write_file File.write(@filename, contents) end |