module Sequel::Plugins::SubsetConditions::DatasetModuleMethods
Public Instance Methods
Source
# File lib/sequel/plugins/subset_conditions.rb 66 def exclude(name, *args, &block) 67 super 68 cond = args 69 cond = cond.first if cond.size == 1 70 define_method(:"#{name}_conditions"){Sequel.~(filter_expr(cond, &block))} 71 end
Also create a method that returns the conditions the filter uses.
Calls superclass method
Source
# File lib/sequel/plugins/subset_conditions.rb 58 def where(name, *args, &block) 59 super 60 cond = args 61 cond = cond.first if cond.size == 1 62 define_method(:"#{name}_conditions"){filter_expr(cond, &block)} 63 end
Also create a method that returns the conditions the filter uses.
Calls superclass method
Source
# File lib/sequel/plugins/subset_conditions.rb 85 def where_all(name, *args) 86 _where_any_all(:&, name, args) 87 end
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))
Source
# File lib/sequel/plugins/subset_conditions.rb 101 def where_any(name, *args) 102 _where_any_all(:|, name, args) 103 end
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))
Private Instance Methods
Source
# File lib/sequel/plugins/subset_conditions.rb 109 def _where_any_all(meth, name, args) 110 ds = model.dataset 111 # #bind used here because the dataset module may not yet be included in the model's dataset 112 where(name, Sequel.send(meth, *args.map{|a| self.instance_method(:"#{a}_conditions").bind(ds).call})) 113 end