Sha256: 2048bf7c2501ced6bacbd82643b2723646456733b2732d141fd9c49817f135aa

Contents?: true

Size: 743 Bytes

Versions: 2

Compression:

Stored size: 743 Bytes

Contents

module Trestle
  module Search
    module Resource
      extend ActiveSupport::Concern

      included do
        # Include custom #collection method on Resource instance
        prepend Collection

        # Include custom #collection method on Resource class
        singleton_class.send(:prepend, Collection)
      end

      module Collection
        def collection(params={})
          if searchable?
            search(params[:q].presence, params)
          else
            super
          end
        end

        def search(query, params={})
          adapter.search(query, params)
        end
      end

      module ClassMethods
        def searchable?
          adapter.respond_to?(:search)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trestle-search-0.4.1 lib/trestle/search/resource.rb
trestle-search-0.4.0 lib/trestle/search/resource.rb