File: active_record_refind.rb

package info (click to toggle)
ruby-test-prof 0.12.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 508 kB
  • sloc: ruby: 4,075; makefile: 4
file content (20 lines) | stat: -rw-r--r-- 517 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

module TestProf
  module Ext
    # Adds `ActiveRecord::Base#refind` method (through refinement)
    module ActiveRecordRefind
      refine ActiveRecord::Base do
        # Returns new reloaded record.
        #
        # Unlike `reload` this method returns
        # completely re-initialized instance.
        #
        # We need it to make sure that the state is clean.
        def refind
          self.class.find(send(self.class.primary_key))
        end
      end
    end
  end
end