File: dataset_module.rb

package info (click to toggle)
ruby-sequel 5.63.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,408 kB
  • sloc: ruby: 113,747; makefile: 3
file content (33 lines) | stat: -rw-r--r-- 906 bytes parent folder | download | duplicates (4)
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
# frozen-string-literal: true

module Sequel
  class Model
    # This Module subclass is used by Model.dataset_module
    # to add dataset methods to classes.  In addition to the
    # methods offered by Dataset::DatasetModule, it also
    # automatically creates class methods for public dataset
    # methods.
    class DatasetModule < Dataset::DatasetModule
      # Store the model related to this dataset module.
      def initialize(model)
        @model = model
      end

      # Alias for where.
      def subset(name, *args, &block)
        where(name, *args, &block)
      end

      private

      # Add a class method to the related model that
      # calls the dataset method of the same name.
      def method_added(meth)
        @model.send(:def_model_dataset_method, meth) if public_method_defined?(meth)
        super
      end
    end

    @dataset_module_class = DatasetModule
  end
end