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_arguments(potential_cruft, arguments) ⇒ Object
- .record_invocation(potential_cruft) ⇒ Object
- .record_stack(potential_cruft) ⇒ Object
Class Method Details
.filtered_stack ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/is_this_used/cruft_tracker.rb', line 46 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_arguments(potential_cruft, arguments) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/is_this_used/cruft_tracker.rb', line 61 def self.record_arguments(potential_cruft, arguments) arguments_hash = Digest::MD5.hexdigest(arguments.to_json) potential_cruft_argument = PotentialCruftArgument.find_by( arguments_hash: arguments_hash ) potential_cruft_argument ||= begin PotentialCruftArgument.create( potential_cruft: potential_cruft, arguments_hash: arguments_hash, arguments: arguments ) rescue ActiveRecord::RecordNotUnique PotentialCruftArgument.find_by( arguments_hash: arguments_hash ) end potential_cruft_argument.with_lock do potential_cruft_argument.occurrences += 1 potential_cruft_argument.save! 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 37 38 39 40 41 42 43 44 |
# 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( stack_hash: stack_hash ) potential_cruft_stack ||= begin PotentialCruftStack.create( potential_cruft: potential_cruft, stack_hash: stack_hash, stack: stack ) rescue ActiveRecord::RecordNotUnique PotentialCruftStack.find_by( stack_hash: stack_hash ) end potential_cruft_stack.with_lock do potential_cruft_stack.reload potential_cruft_stack.occurrences += 1 potential_cruft_stack.save! end end |