| Class | Sequel::Dataset::DatasetModule |
| In: |
lib/sequel/dataset/dataset_module.rb
|
| Parent: | ::Module |
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
Define a method in the module
# File lib/sequel/dataset/dataset_module.rb, line 29
29: def self.def_dataset_caching_method(mod, meth)
30: mod.send(:define_method, meth) do |name, *args, &block|
31: if block
32: define_method(name){public_send(meth, *args, &block)}
33: else
34: key = "_#{meth}_#{name}_ds""_#{meth}_#{name}_ds"
35: define_method(name) do
36: cached_dataset(key){public_send(meth, *args)}
37: end
38: end
39: end
40: end