Module | Sequel::Plugins::InvertedSubsets |
In: |
lib/sequel/plugins/inverted_subsets.rb
|
The inverted_subsets plugin adds another method for each defined subset, which inverts the condition supplied. By default, inverted subset method names are prefixed with not_.
You can change the prefix, or indeed entirely customise the inverted names, by passing a block to the plugin configuration:
# Use an exclude_ prefix for inverted subsets instead of not_ Album.plugin(:inverted_subsets){|name| "exclude_#{name}"}
Usage:
# Add inverted subsets in the Album class Album.plugin :inverted_subsets # This will now create two methods, published and not_published Album.dataset_module do where :published, published: true end Album.published.sql # SELECT * FROM albums WHERE (published IS TRUE) Album.not_published.sql # SELECT * FROM albums WHERE (published IS NOT TRUE)
# File lib/sequel/plugins/inverted_subsets.rb, line 32 32: def self.apply(mod, &block) 33: mod.instance_exec do 34: @dataset_module_class = Class.new(@dataset_module_class) do 35: include DatasetModuleMethods 36: if block 37: define_method(:inverted_subset_name, &block) 38: private :inverted_subset_name 39: end 40: end 41: end 42: end