aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/deduplicable.rb
blob: fb2fd60bbc2679903b21eeee92f9ae4b71eaf742 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters # :nodoc:
    module Deduplicable
      extend ActiveSupport::Concern

      module ClassMethods
        def registry
          @registry ||= {}
        end

        def new(*)
          super.deduplicate
        end
      end

      def deduplicate
        self.class.registry[self] ||= deduplicated
      end
      alias :-@ :deduplicate

      private
        def deduplicated
          freeze
        end
    end
  end
end