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.78.0 lib/sequel/dataset/dataset_module.rb
sequel-5.77.0 lib/sequel/dataset/dataset_module.rb
sequel-5.76.0 lib/sequel/dataset/dataset_module.rb
sequel-5.75.0 lib/sequel/dataset/dataset_module.rb
sequel-5.74.0 lib/sequel/dataset/dataset_module.rb
sequel-5.73.0 lib/sequel/dataset/dataset_module.rb
sequel-5.72.0 lib/sequel/dataset/dataset_module.rb
sequel-5.71.0 lib/sequel/dataset/dataset_module.rb
sequel-5.70.0 lib/sequel/dataset/dataset_module.rb
sequel-5.69.0 lib/sequel/dataset/dataset_module.rb
sequel-5.68.0 lib/sequel/dataset/dataset_module.rb
sequel-5.67.0 lib/sequel/dataset/dataset_module.rb
sequel-5.66.0 lib/sequel/dataset/dataset_module.rb
sequel-5.65.0 lib/sequel/dataset/dataset_module.rb
sequel-5.64.0 lib/sequel/dataset/dataset_module.rb
sequel-5.63.0 lib/sequel/dataset/dataset_module.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/sequel-5.62.0/lib/sequel/dataset/dataset_module.rb
sequel-5.62.0 lib/sequel/dataset/dataset_module.rb
sequel-5.61.0 lib/sequel/dataset/dataset_module.rb
sequel-5.60.1 lib/sequel/dataset/dataset_module.rb