Class: Sequel::Model::DatasetModule

Inherits:
Module
  • Object
show all
Defined in:
lib/sequel/model/dataset_module.rb

Overview

This Module subclass is used by Model.dataset_module to add dataset methods to classes. It adds a couple of features standard Modules, allowing you to use the same subset method you can call on Model, as well as making sure that public methods added to the module automatically have class methods created for them.

Direct Known Subclasses

Associations::DatasetModule

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ DatasetModule

Store the model related to this dataset module.



13
14
15
# File 'lib/sequel/model/dataset_module.rb', line 13

def initialize(model)
  @model = model
end

Class Method Details

.def_dataset_caching_method(mod, meth) ⇒ Object

Define a method in the module



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sequel/model/dataset_module.rb', line 48

def self.def_dataset_caching_method(mod, meth)
  mod.send(:define_method, meth) do |name, *args, &block|
    if block
      @model.def_dataset_method(name){send(meth, *args, &block)}
    else
      key = :"_#{meth}_#{name}_ds"
      @model.def_dataset_method(name) do
        cached_dataset(key){send(meth, *args)}
      end
    end
  end
end

Instance Method Details

#subset(name, *args, &block) ⇒ Object

Define a named filter for this dataset, see Model.subset for details.



19
20
21
# File 'lib/sequel/model/dataset_module.rb', line 19

def subset(name, *args, &block)
  @model.subset(name, *args, &block)
end

#where(name, *args, &block) ⇒ Object

Alias for subset



24
25
26
# File 'lib/sequel/model/dataset_module.rb', line 24

def where(name, *args, &block)
  subset(name, *args, &block)
end