The subset_conditions plugin creates an additional *_conditions method for every ‘subset`, `where`, and `exclude` method call in a dataset_module block. This method returns the filter conditions, which can be useful if you want to use the conditions for a separate filter or combine them with OR. It also supports where_all and where_any dataset_module methods for combining multiple dataset method filters with AND or OR.
Usage:
# Add subset_conditions in the Album class Album.plugin :subset_conditions Album.dataset_module do # This will now create a published_conditions method where :published, published: true # This will now create a not_bad_conditions method exclude :not_bad, :bad # This will create good_and_available and # good_and_available_conditions methods where_all :good_and_available, :published, :not_bad # This will create good_or_available and # good_or_available_conditions methods where_any :good_or_available, :published, :not_bad end Album.where(Album.published_conditions).sql # SELECT * FROM albums WHERE (published IS TRUE) Album.exclude(Album.published_conditions).sql # SELECT * FROM albums WHERE (published IS NOT TRUE) Album.where(Album.published_conditions | {ready: true}).sql # SELECT * FROM albums WHERE ((published IS TRUE) OR (ready IS TRUE)) Album.good_and_available.sql SELECT * FROM albums WHERE ((published IS TRUE) AND NOT bad) Album.good_or_available.sql SELECT * FROM albums WHERE ((published IS TRUE) OR NOT bad)
Included modules
Classes and Modules
Public Class methods
apply(model, &block)
[show source]
# File lib/sequel/plugins/subset_conditions.rb 48 def self.apply(model, &block) 49 model.instance_exec do 50 @dataset_module_class = Class.new(@dataset_module_class) do 51 include DatasetModuleMethods 52 end 53 end 54 end