module SimpleListing::Filterable

Public Instance Methods

filter_params() click to toggle source
# File lib/simple_listing/filterable.rb, line 34
def filter_params
  params[config[:filter_params_key]]
end
perform() click to toggle source
Calls superclass method
# File lib/simple_listing/filterable.rb, line 28
def perform
  super
  apply_filters if should_be_filtered?
  scope
end
should_be_filtered?() click to toggle source
# File lib/simple_listing/filterable.rb, line 38
def should_be_filtered?
  filter_params && filter_params.respond_to?(:each)
end

Private Instance Methods

apply_filters() click to toggle source
# File lib/simple_listing/filterable.rb, line 44
def apply_filters
  filter_params.each do |key, value|
    guard("incorrect filter key '#{key}'") { filterable_by?(key) }
    self.scope = if handler = filtering_handlers[key]
                   handler.call(scope, value, self)
                 else
                   scope.where(key => value)
                 end
  end
end
filterable_by?(key) click to toggle source
# File lib/simple_listing/filterable.rb, line 55
def filterable_by?(key)
  key.to_s.in? filterable_keys
end