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.47.0 lib/sequel/dataset/dataset_module.rb
sequel-5.46.0 lib/sequel/dataset/dataset_module.rb
sequel-5.45.0 lib/sequel/dataset/dataset_module.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/sequel-5.38.0/lib/sequel/dataset/dataset_module.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/sequel-5.43.0/lib/sequel/dataset/dataset_module.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/sequel-5.44.0/lib/sequel/dataset/dataset_module.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/sequel-5.41.0/lib/sequel/dataset/dataset_module.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/sequel-5.41.0/lib/sequel/dataset/dataset_module.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/sequel-5.44.0/lib/sequel/dataset/dataset_module.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/sequel-5.39.0/lib/sequel/dataset/dataset_module.rb
sequel-5.44.0 lib/sequel/dataset/dataset_module.rb
sequel-5.43.0 lib/sequel/dataset/dataset_module.rb
sequel-5.42.0 lib/sequel/dataset/dataset_module.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/sequel-5.41.0/lib/sequel/dataset/dataset_module.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/sequel-5.39.0/lib/sequel/dataset/dataset_module.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/sequel-5.41.0/lib/sequel/dataset/dataset_module.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/sequel-5.38.0/lib/sequel/dataset/dataset_module.rb
sequel-5.41.0 lib/sequel/dataset/dataset_module.rb
sequel-5.40.0 lib/sequel/dataset/dataset_module.rb
sequel-5.39.0 lib/sequel/dataset/dataset_module.rb