File: deprecated_singleton_class_methods.rb

package info (click to toggle)
ruby-sequel 5.97.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,188 kB
  • sloc: ruby: 123,115; makefile: 3
file content (42 lines) | stat: -rw-r--r-- 1,440 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen-string-literal: true

module Sequel
  class Dataset
    # This module implements methods to support deprecated use of extensions registered
    # not using a module.  In such cases, for backwards compatibility, Sequel has to use
    # a singleton class for the dataset.
    module DeprecatedSingletonClassMethods
      # Load the extension into a clone of the receiver.
      def extension(*a)
        c = _clone(:freeze=>false)
        c.send(:_extension!, a)
        c.freeze
      end

      # Extend the cloned of the receiver with the given modules, instead of the default
      # approach of creating a subclass of the receiver's class and including the modules
      # into that.
      def with_extend(*mods, &block)
        c = _clone(:freeze=>false)
        c.extend(*mods) unless mods.empty?
        c.extend(Sequel.set_temp_name(DatasetModule.new(&block)){"Sequel::Dataset::_DatasetModule(#{block.source_location.join(':')})"}) if block
        c.freeze
      end

      private

      # Load the extensions into the receiver.
      def _extension!(exts)
        Sequel.extension(*exts)
        exts.each do |ext|
          if pr = Sequel.synchronize{EXTENSIONS[ext]}
            pr.call(self)
          else
            raise(Error, "Extension #{ext} does not have specific support handling individual datasets (try: Sequel.extension #{ext.inspect})")
          end
        end
        self
      end
    end
  end
end