Sha256: e9532064aca35e1a0b1199e59f7195868d381170082c32a0eaf0746bffd7f0b3

Contents?: true

Size: 1.45 KB

Versions: 114

Compression:

Stored size: 1.45 KB

Contents

# frozen-string-literal: true

module Sequel
  class Dataset
    # This Module subclass is used by Database#extend_datasets
    # and Dataset#with_extend to add dataset methods to classes.
    # It adds some helper methods inside the module that can define
    # named methods on the dataset instances which do specific actions.
    # For example:
    #
    #   DB.extend_datasets do
    #     order :by_id, :id
    #     select :with_id_and_name, :id, :name
    #     where :active, :active
    #   end
    #
    #   DB[:table].active.with_id_and_name.by_id
    #   # SELECT id, name FROM table WHERE active ORDER BY id
    class DatasetModule < ::Module
      meths = (<<-METHS).split.map(&:to_sym)
        where exclude exclude_having having
        distinct grep group group_and_count group_append 
        limit offset order order_append order_prepend reverse 
        select select_all select_append select_group server
      METHS

      # Define a method in the module
      def self.def_dataset_caching_method(mod, meth)
        mod.send(:define_method, meth) do |name, *args, &block|
          if block
            define_method(name){public_send(meth, *args, &block)}
          else
            key = :"_#{meth}_#{name}_ds"
            define_method(name) do
              cached_dataset(key){public_send(meth, *args)}
            end
          end
        end
      end

      meths.each do |meth|
        def_dataset_caching_method(self, meth)
      end
    end
  end
end

Version data entries

114 entries across 97 versions & 2 rubygems

Version Path
sequel-5.60.0 lib/sequel/dataset/dataset_module.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/sequel-5.59.0/lib/sequel/dataset/dataset_module.rb
sequel-5.59.0 lib/sequel/dataset/dataset_module.rb
sequel-5.58.0 lib/sequel/dataset/dataset_module.rb
sequel-5.57.0 lib/sequel/dataset/dataset_module.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/sequel-5.56.0/lib/sequel/dataset/dataset_module.rb
sequel-5.56.0 lib/sequel/dataset/dataset_module.rb
sequel-5.55.0 lib/sequel/dataset/dataset_module.rb
sequel-5.54.0 lib/sequel/dataset/dataset_module.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/sequel-5.53.0/lib/sequel/dataset/dataset_module.rb
sequel-5.53.0 lib/sequel/dataset/dataset_module.rb
sequel-5.52.0 lib/sequel/dataset/dataset_module.rb
sequel-5.51.0 lib/sequel/dataset/dataset_module.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/dataset/dataset_module.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/sequel-5.50.0/lib/sequel/dataset/dataset_module.rb
sequel-5.50.0 lib/sequel/dataset/dataset_module.rb
sequel-5.49.0 lib/sequel/dataset/dataset_module.rb
sequel-5.48.0 lib/sequel/dataset/dataset_module.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/dataset/dataset_module.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/sequel-5.47.0/lib/sequel/dataset/dataset_module.rb