lib/trestle/search/resource.rb in trestle-search-0.2.1 vs lib/trestle/search/resource.rb in trestle-search-0.3.0
- old
+ new
@@ -1,23 +1,31 @@
module Trestle
module Search
module Resource
- attr_writer :search
+ extend ActiveSupport::Concern
- def initialize_collection(params)
- if searchable?
- search(params[:q], params)
- else
- super(params)
- end
+ included do
+ # Include custom #collection method on Resource instance
+ prepend Collection
+
+ # Include custom #collection method on Resource class
+ singleton_class.send(:prepend, Collection)
end
- def search(query, params)
- instance_exec(query.presence, params, &@search)
+ module Collection
+ def collection(params)
+ if searchable?
+ adapter.search(params[:q].presence, params)
+ else
+ super
+ end
+ end
end
- def searchable?
- @search
+ module ClassMethods
+ def searchable?
+ adapter.respond_to?(:search)
+ end
end
end
end
end