module Sequel::Plugins::SubsetConditions::DatasetModuleMethods

  1. lib/sequel/plugins/subset_conditions.rb

Methods

Public Instance

  1. exclude
  2. where
  3. where_all
  4. where_any

Public Instance methods

exclude(name, *args, &block)

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

[show 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
where(name, *args, &block)

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

[show 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
where_all(name, *args)

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))
[show source]
   # File lib/sequel/plugins/subset_conditions.rb
85 def where_all(name, *args)
86   _where_any_all(:&, name, args)
87 end
where_any(name, *args)

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))
[show source]
    # File lib/sequel/plugins/subset_conditions.rb
101 def where_any(name, *args)
102   _where_any_all(:|, name, args)
103 end