module Sequel::Plugins::SubsetConditions::DatasetModuleMethods

Public Instance Methods

exclude(name, *args, &block) click to toggle source

Also create a method that returns the conditions the filter uses.

Calls superclass method
   # File lib/sequel/plugins/subset_conditions.rb
67 def exclude(name, *args, &block)
68   super
69   cond = args
70   cond = cond.first if cond.size == 1
71   define_method(:"#{name}_conditions"){Sequel.~(filter_expr(cond, &block))}
72 end
where(name, *args, &block) click to toggle source

Also create a method that returns the conditions the filter uses.

Calls superclass method
   # File lib/sequel/plugins/subset_conditions.rb
59 def where(name, *args, &block)
60   super
61   cond = args
62   cond = cond.first if cond.size == 1
63   define_method(:"#{name}_conditions"){filter_expr(cond, &block)}
64 end
where_all(name, *args) click to toggle source

Create a method that combines filters from already registered dataset methods, and filters for rows where all of the conditions are satisfied.

Employee.dataset_module do
  where :active, active: true
  where :started, Sequel::CURRENT_DATE <= :start_date
  where_all(:active_and_started, :active, :started)
end

Employee.active_and_started.sql
# SELECT * FROM employees WHERE ((active IS TRUE) AND (CURRENT_DATE <= start_date))
   # File lib/sequel/plugins/subset_conditions.rb
86 def where_all(name, *args)
87   _where_any_all(:&, name, args)
88 end
where_any(name, *args) click to toggle source

Create a method that combines filters from already registered dataset methods, and filters for rows where any of the conditions are satisfied.

Employee.dataset_module do
  where :active, active: true
  where :started, Sequel::CURRENT_DATE <= :start_date
  where_any(:active_or_started, :active, :started)
end

Employee.active_or_started.sql
# SELECT * FROM employees WHERE ((active IS TRUE) OR (CURRENT_DATE <= start_date))
    # File lib/sequel/plugins/subset_conditions.rb
102 def where_any(name, *args)
103   _where_any_all(:|, name, args)
104 end

Private Instance Methods

_where_any_all(meth, name, args) click to toggle source

Backbone of where_any and where_all

    # File lib/sequel/plugins/subset_conditions.rb
110 def _where_any_all(meth, name, args)
111   ds = model.dataset
112   # #bind used here because the dataset module may not yet be included in the model's dataset
113   where(name, Sequel.send(meth, *args.map{|a| self.instance_method(:"#{a}_conditions").bind(ds).call}))
114 end