module Babik::QuerySet::Filterable

Functionality related to the DELETE operation

Public Instance Methods

exclude!(filter) click to toggle source

Exclude objects according to some criteria. @return [QuerySet] Reference to self.

# File lib/babik/queryset/mixins/filterable.rb, line 9
def exclude!(filter)
  _filter(filter, 'exclusion')
  self
end
filter!(filter) click to toggle source

Select objects according to some criteria. @param filter [Array, Hash] if array, it is considered an disjunction (OR clause),

if a hash, it is considered a conjunction (AND clause).

@return [QuerySet] Reference to self.

# File lib/babik/queryset/mixins/filterable.rb, line 18
def filter!(filter)
  _filter(filter, 'inclusion')
  self
end
get(filter) click to toggle source

Get an single element @param filter [Array, Hash] if array, it is considered an disjunction (OR clause),

if a hash, it is considered a conjunction (AND clause).

@raise [RuntimeError] Exception:

'Multiple objects returned' if more than one object matches the condition.
'Does not exist' if no object match the conditions.

@return [ActiveRecord::Base] object that matches the filter.

# File lib/babik/queryset/mixins/filterable.rb, line 30
def get(filter)
  result_ = self.filter(filter).all
  result_count = result_.count
  raise 'Does not exist' if result_count.zero?
  raise 'Multiple objects returned' if result_count > 1
  result_.first
end

Private Instance Methods

_filter(filter, filter_type) click to toggle source

Select the objects according to some criteria. @param filter [Array, Hash] if array, it is considered an disjunction (OR clause),

if a hash, it is considered a conjunction (AND clause).

@param filter_type [String] Filter type. Must be 'inclusion' or 'exclusion'. @raise [NoMethodError] if filter_type is not 'inclusion' nor 'exclusion'.

# File lib/babik/queryset/mixins/filterable.rb, line 45
def _filter(filter, filter_type)
  @_where.send("add_#{filter_type}_filter", filter)
end