- [feature] Added
param?
method toSearch::Base
(@rstankov)
- [feature] Added
:with
and block support to enum (@hschne)
- [fix] convert enum values to strings (@Postmodum37)
- [feature] Added
SearchObject::Base#params=
method, to reset search results (@rstankov) - [change]
option :orderBy, enum: %(price date)
, now expects a methodapply_order_by_x
, instead ofapply_orderBy_with_
(backward incompatible) (@rstankov)
- [feature] Added
default:
option tosort_by
plugin (@rstankov)
class ProductSearch
include SearchObject.module(:sorting)
scope { Product.all }
sort_by :name, :price, :created_at, default: 'price asc'
end
- [feature] Added
enum
plugin (@rstankov)
class ProductSearch
include SearchObject.module(:enum)
scope { Product.all }
option :order, enum: %w(popular date)
private
# Gets called when order with 'popular' is given
def apply_order_with_popular(scope)
scope.by_popularity
end
# Gets called when order with 'date' is given
def apply_order_with_date(scope)
scope.by_date
end
# Gets called when invalid enum is given
def handle_invalid_order(scope, invalid_value)
scope
end
end
- [feature] Scope is executed in context of SearchObject::Base context (@rstankov)
class ProductSearch
include SearchObject.module
scope { @shop.products }
def initialize(shop)
@shop = shop
super
end
end
- [feature] Passing nil as
scope
in constructor, falls back to default scope (@rstankov)
- [fix] Fix a warning due to Rails 5
ActionController::Parameters
not being a Hash (@rstankov) - [fix] Ensure
sort_by
prefixes with table_name. (@andreasklinger)
- [fix] Fix a bug in inheriting search objects (@avlazarov)
- [feature] Search objects now can be inherited (@rstankov)
class BaseSearch
include SearchObject.module
# ... options and configuration
end
class ProductSearch < BaseSearch
scope { Product }
end
-
[feature] Use instance method for straight dispatch (@gsamokovarov)
class ProductSearch include SearchObject.module scope { Product.all } option :date, with: :parse_dates private def parse_dates(scope, value) # some "magic" method to parse dates end end
-
[feature] Added min_per_page and max_per_page to paging plugin (@rstankov)
-
[change] Default paging behaves more like 'kaminari' and 'will_paginate' by treating 1 page as 0 index (backward incompatible) (@rstankov)
-
[feature] Raise
SearchObject::MissingScopeError
when no scope is provided (@rstankov) -
[change] Replace position arguments with Hash of options (backward incompatible) (@rstankov)
- Search.new params[:f], params[:page] + Search.new filters: params[:f], page: params[:page]
-
[feature] Added
.results
shortcut fornew(*arg).results
(@rstankov) -
[fix] Fix wrong limit and offset in default paging (@rstankov)
- Initial release (@rstankov)