Class: Usergrid::Collection
- Includes:
- Enumerable
- Defined in:
- lib/usergrid/core/collection.rb
Constant Summary
Constants inherited from Resource
Resource::DEFAULT_API_URL, Resource::RESERVED, Resource::TYPE_HEADERS
Instance Attribute Summary collapse
-
#iterator_follows_cursor ⇒ Object
Returns the value of attribute iterator_follows_cursor.
Attributes inherited from Resource
#api_url, #current_user, #response
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
- #collection ⇒ Object
- #create_entity(data) ⇒ Object (also: #create_entities)
- #cursor ⇒ Object
-
#delete_query(query = nil, options = {}) ⇒ Object
options: ‘reversed’, ‘start’, ‘cursor’, ‘limit’, ‘permission’.
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #entities ⇒ Object
-
#follow_cursor ⇒ Object
use in conjunction with each() like: collection.follow_cursor.each {|e| }.
-
#initialize(url, api_url, options = {}, response = nil) ⇒ Collection
constructor
A new instance of Collection.
- #next_page ⇒ Object
-
#query(query = nil, options = {}) ⇒ Object
options: ‘reversed’, ‘start’, ‘cursor’, ‘limit’, ‘permission’.
-
#save ⇒ Object
does not save entities! just fields (eg. ‘name’).
- #size ⇒ Object
-
#update_query(updates, query = nil, options = {}) ⇒ Object
options: ‘reversed’, ‘start’, ‘cursor’, ‘limit’, ‘permission’.
Methods inherited from Entity
#data, #data?, #resource, #to_json, #to_s
Methods inherited from Resource
#api_resource, #application, #auth_token, #auth_token=, #entity, #get, #logged_in?, #login, #logout, #management, #post, #put
Constructor Details
#initialize(url, api_url, options = {}, response = nil) ⇒ Collection
7 8 9 10 |
# File 'lib/usergrid/core/collection.rb', line 7 def initialize(url, api_url, ={}, response=nil) super url, api_url, , response @iterator_follows_cursor = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Usergrid::Entity
Instance Attribute Details
#iterator_follows_cursor ⇒ Object
Returns the value of attribute iterator_follows_cursor.
5 6 7 |
# File 'lib/usergrid/core/collection.rb', line 5 def iterator_follows_cursor @iterator_follows_cursor end |
Instance Method Details
#[](k) ⇒ Object
21 22 23 |
# File 'lib/usergrid/core/collection.rb', line 21 def [](k) entities[k] end |
#[]=(k, v) ⇒ Object
25 26 27 |
# File 'lib/usergrid/core/collection.rb', line 25 def []=(k,v) raise "unsupported operation" end |
#collection ⇒ Object
12 13 14 |
# File 'lib/usergrid/core/collection.rb', line 12 def collection self end |
#create_entity(data) ⇒ Object Also known as: create_entities
49 50 51 |
# File 'lib/usergrid/core/collection.rb', line 49 def create_entity(data) self.post data end |
#cursor ⇒ Object
86 87 88 |
# File 'lib/usergrid/core/collection.rb', line 86 def cursor response.data['cursor'] end |
#delete_query(query = nil, options = {}) ⇒ Object
options: ‘reversed’, ‘start’, ‘cursor’, ‘limit’, ‘permission’
63 64 65 66 67 68 |
# File 'lib/usergrid/core/collection.rb', line 63 def delete_query(query=nil, ={}) = .symbolize_keys query_params = query ? .merge({ql: query}) : self.delete({params: query_params }) self end |
#each(&block) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/usergrid/core/collection.rb', line 34 def each(&block) entities.each &block while cursor next_page entities.each &block end if iterator_follows_cursor end |
#empty? ⇒ Boolean
82 83 84 |
# File 'lib/usergrid/core/collection.rb', line 82 def empty? entities.empty? end |
#entities ⇒ Object
16 17 18 19 |
# File 'lib/usergrid/core/collection.rb', line 16 def entities get unless response response.entities end |
#follow_cursor ⇒ Object
use in conjunction with each() like: collection.follow_cursor.each {|e| }
43 44 45 46 47 |
# File 'lib/usergrid/core/collection.rb', line 43 def follow_cursor my_clone = self.clone my_clone.iterator_follows_cursor = true my_clone end |
#next_page ⇒ Object
90 91 92 |
# File 'lib/usergrid/core/collection.rb', line 90 def next_page query(nil, query_params.merge({cursor: cursor})) end |
#query(query = nil, options = {}) ⇒ Object
options: ‘reversed’, ‘start’, ‘cursor’, ‘limit’, ‘permission’
71 72 73 74 75 76 |
# File 'lib/usergrid/core/collection.rb', line 71 def query(query=nil, ={}) = .symbolize_keys query_params = query ? .merge({ql: query}) : self.get({params: query_params }) self end |
#save ⇒ Object
does not save entities! just fields (eg. ‘name’)
30 31 32 |
# File 'lib/usergrid/core/collection.rb', line 30 def save super save end |
#size ⇒ Object
78 79 80 |
# File 'lib/usergrid/core/collection.rb', line 78 def size entities.size end |
#update_query(updates, query = nil, options = {}) ⇒ Object
options: ‘reversed’, ‘start’, ‘cursor’, ‘limit’, ‘permission’
55 56 57 58 59 60 |
# File 'lib/usergrid/core/collection.rb', line 55 def update_query(updates, query=nil, ={}) = .symbolize_keys query_params = query ? .merge({ql: query}) : self.put(updates, {params: query_params }) self end |