Sha256: cf9e3f250ab4bb4b6b0cb9565ce05f75d562fb017b7a8daedfe3f0230d0f692f

Contents?: true

Size: 1.46 KB

Versions: 13

Compression:

Stored size: 1.46 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 select_prepend 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

13 entries across 13 versions & 1 rubygems

Version Path
sequel-5.90.0 lib/sequel/dataset/dataset_module.rb
sequel-5.89.0 lib/sequel/dataset/dataset_module.rb
sequel-5.88.0 lib/sequel/dataset/dataset_module.rb
sequel-5.87.0 lib/sequel/dataset/dataset_module.rb
sequel-5.86.0 lib/sequel/dataset/dataset_module.rb
sequel-5.85.0 lib/sequel/dataset/dataset_module.rb
sequel-5.84.0 lib/sequel/dataset/dataset_module.rb
sequel-5.83.1 lib/sequel/dataset/dataset_module.rb
sequel-5.83.0 lib/sequel/dataset/dataset_module.rb
sequel-5.82.0 lib/sequel/dataset/dataset_module.rb
sequel-5.81.0 lib/sequel/dataset/dataset_module.rb
sequel-5.80.0 lib/sequel/dataset/dataset_module.rb
sequel-5.79.0 lib/sequel/dataset/dataset_module.rb