Module: AthenaResource::Finders::ClassMethods
- Defined in:
- lib/athena_resource/finders.rb
Instance Method Summary collapse
-
#method_missing(method_id, *arguments) ⇒ Object
This method will translate find_by_some_object_id into …?someObjectId=9.
-
#query(query_str) ⇒ Object
Can be used when searching for a range because you can’t dupe keys in a hash For example: datetime=lt2011-03-02&datetime=gt2010-05-05.
- #search_index(search_query, organization, limit = 10) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *arguments) ⇒ Object
This method will translate find_by_some_object_id into …?someObjectId=9
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/athena_resource/finders.rb', line 30 def method_missing(method_id, *arguments) if method_id.to_s =~ /find_by_(\w+)/ arg = arguments[0] term = $1.camelcase(:lower) find(:all, :params => { term => arg }) else super end end |
Instance Method Details
#query(query_str) ⇒ Object
Can be used when searching for a range because you can’t dupe keys in a hash For example: datetime=lt2011-03-02&datetime=gt2010-05-05
19 20 21 22 23 24 25 26 27 |
# File 'lib/athena_resource/finders.rb', line 19 def query(query_str) #Neither CGI::Escape nor URI.escape worked here #CGI::escape escaped everything and ATHENA threw 400 #URI.escape failed to change the + to %2B which is really the only thing I wanted it to do query_str.gsub!(/\+/,'%2B') connection.get(self.collection_path + "?" + query_str, self.headers) end |
#search_index(search_query, organization, limit = 10) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/athena_resource/finders.rb', line 6 def search_index(search_query, organization, limit=10) if search_query.blank? search_query = '' else search_query.concat(' AND ') end search_query.concat("organizationId:").concat("#{organization.id}") find(:all, :params => { '_q' => search_query, '_limit' => limit}) end |