Class: IsThisUsed::CruftTracker::Recorder
- Inherits:
-
Object
- Object
- IsThisUsed::CruftTracker::Recorder
- Defined in:
- lib/is_this_used/cruft_tracker.rb
Class Method Summary collapse
- .filtered_stack ⇒ Object
- .record_invocation(potential_cruft) ⇒ Object
- .record_stack(potential_cruft) ⇒ Object
Class Method Details
.filtered_stack ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/is_this_used/cruft_tracker.rb', line 38 def self.filtered_stack caller_locations.reject do |location| location.path.match?( %r{\/lib\/is_this_used\/(cruft_tracker.rb|util\/log_suppressor.rb)$} ) end.map do |location| { path: location.path, label: location.label, base_label: location.base_label, lineno: location.lineno } end end |
.record_invocation(potential_cruft) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/is_this_used/cruft_tracker.rb', line 9 def self.record_invocation(potential_cruft) PotentialCruft.increment_counter( :invocations, potential_cruft.id, touch: true ) record_stack(potential_cruft) end |
.record_stack(potential_cruft) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/is_this_used/cruft_tracker.rb', line 18 def self.record_stack(potential_cruft) stack = filtered_stack stack_hash = Digest::MD5.hexdigest(stack.to_json) potential_cruft_stack = PotentialCruftStack.find_by( potential_cruft: potential_cruft, stack_hash: stack_hash ) potential_cruft_stack ||= PotentialCruftStack.new( potential_cruft: potential_cruft, stack_hash: stack_hash, stack: stack ) potential_cruft_stack.occurrences += 1 potential_cruft_stack.save end |