Sha256: d111bdf46f82b5f9469de6ed203118bb8c805df1d7d7f14d00b1664862e4bf0e

Contents?: true

Size: 778 Bytes

Versions: 5

Compression:

Stored size: 778 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?
            query = params[:q].presence
            search(query, params) || super
          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

5 entries across 5 versions & 1 rubygems

Version Path
trestle-search-0.5.1 lib/trestle/search/resource.rb
trestle-search-0.5.0 lib/trestle/search/resource.rb
trestle-search-0.5.0.pre lib/trestle/search/resource.rb
trestle-search-0.4.3 lib/trestle/search/resource.rb
trestle-search-0.4.2 lib/trestle/search/resource.rb