Module: Sequel::Plugins::SubsetConditions::DatasetModuleMethods
- Defined in:
- lib/sequel/plugins/subset_conditions.rb
Instance Method Summary collapse
-
#exclude(name, *args, &block) ⇒ Object
Also create a method that returns the conditions the filter uses.
-
#where(name, *args, &block) ⇒ Object
Also create a method that returns the conditions the filter uses.
-
#where_all(name, *args) ⇒ Object
Create a method that combines filters from already registered dataset methods, and filters for rows where all of the conditions are satisfied.
-
#where_any(name, *args) ⇒ Object
Create a method that combines filters from already registered dataset methods, and filters for rows where any of the conditions are satisfied.
Instance Method Details
#exclude(name, *args, &block) ⇒ Object
Also create a method that returns the conditions the filter uses.
66 67 68 69 70 71 |
# File 'lib/sequel/plugins/subset_conditions.rb', line 66 def exclude(name, *args, &block) super cond = args cond = cond.first if cond.size == 1 define_method(:"#{name}_conditions"){Sequel.~(filter_expr(cond, &block))} end |
#where(name, *args, &block) ⇒ Object
Also create a method that returns the conditions the filter uses.
58 59 60 61 62 63 |
# File 'lib/sequel/plugins/subset_conditions.rb', line 58 def where(name, *args, &block) super cond = args cond = cond.first if cond.size == 1 define_method(:"#{name}_conditions"){filter_expr(cond, &block)} end |
#where_all(name, *args) ⇒ Object
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))
85 86 87 |
# File 'lib/sequel/plugins/subset_conditions.rb', line 85 def where_all(name, *args) _where_any_all(:&, name, args) end |
#where_any(name, *args) ⇒ Object
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))
101 102 103 |
# File 'lib/sequel/plugins/subset_conditions.rb', line 101 def where_any(name, *args) _where_any_all(:|, name, args) end |