Sha256: bc039ba84c482a34747dc15fd2cc2bc09c641592eeca69386e4c7d5f198d1cc0

Contents?: true

Size: 969 Bytes

Versions: 5

Compression:

Stored size: 969 Bytes

Contents

module Highrise
  module Searchable
    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      # List By Search Criteria
      # Ex: Highrise::Person.search(:email => "john.doe@example.com", :country => "CA")
      # Available criteria are: city, state, country, zip, phone, email
      def search(options = {})
        raise ArgumentError, "cannot convert #{options}:#{options.class} to hash" if options.kind_of?(String)
        search_params = options.inject({}) { |h, (k, v)| h["criteria[#{k}]"] = v; h }
        # This might have to be changed in the future if other non-pagable resources become searchable
        if self.respond_to?(:find_all_across_pages)
          self.find_all_across_pages(:from => "/#{self.collection_name}/search.xml", :params => search_params)
        else
          self.find(:all, {:from => "/#{self.collection_name}/search.xml", :params => search_params})
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
peterosullivan-highrise-3.0.6 lib/highrise/searchable.rb
peterosullivan-highrise-3.0.5 lib/highrise/searchable.rb
peterosullivan-highrise-3.0.4 lib/highrise/searchable.rb
peterosullivan-highrise-3.0.3 lib/highrise/searchable.rb
peterosullivan-highrise-3.0.2 lib/highrise/searchable.rb