Class: Parse::PointerCollectionProxy
- Inherits:
-
CollectionProxy
- Object
- CollectionProxy
- Parse::PointerCollectionProxy
- Defined in:
- lib/parse/model/associations/pointer_collection_proxy.rb
Overview
A PointerCollectionProxy is a collection proxy that only allows Parse Pointers (Objects) to be part of the collection. This is done by typecasting the collection to a particular Parse class. Ex. An Artist may have several Song objects. Therefore an Artist could have a column :songs, that is an array (collection) of Song (Parse::Object subclass) objects.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#collection ⇒ Array<Parse::Object>
The internal backing store of the collection.
Attributes inherited from CollectionProxy
#delegate, #key, #loaded, #parse_class
Instance Method Summary collapse
-
#add(*items) ⇒ Array<Parse::Object>
Add Parse::Objects to the collection.
-
#add!(*items) ⇒ Object
Atomically add a set of Parse::Objects to this collection.
-
#add_unique!(*items) ⇒ Object
Atomically add a set of Parse::Objects to this collection for those not already in the collection.
-
#as_json(opts = nil) ⇒ Object
Encode the collection as a JSON object of Parse::Pointers.
-
#fetch ⇒ Object
Fetch the set of pointer objects in this collection.
-
#fetch! ⇒ Object
Force fetch the set of pointer objects in this collection.
-
#parse_pointers ⇒ Array<Parse::Pointer>
An array of pointers representing this collection.
-
#remove(*items) ⇒ Array<Parse::Object>
Removes Parse::Objects from the collection.
-
#remove!(*items) ⇒ Object
Atomically remove a set of Parse::Objects to this collection.
Methods inherited from CollectionProxy
#&, #+, #-, #<<, #==, #add_unique, #changes_applied!, #clear, #clear_changes!, #count, #destroy!, #each, #empty?, #first, #flatten, #forward, #initialize, #last, #loaded?, #map, #notify_will_change!, #reload!, #reset!, #rollback!, #second, #select, #set_collection!, #to_a, #uniq, #uniq!, #|
Constructor Details
This class inherits a constructor from Parse::CollectionProxy
Instance Attribute Details
#collection ⇒ Array<Parse::Object>
If you modify this directly, it is highly recommended that you call CollectionProxy#notify_will_change! to notify the dirty tracking system.
The internal backing store of the collection.
24 25 26 27 |
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 24 def collection=(c) notify_will_change! @collection = c end |
Instance Method Details
#add(parse_object) ⇒ Array<Parse::Object> #add(parse_objects) ⇒ Array<Parse::Object>
Add Parse::Objects to the collection.
37 38 39 40 41 42 43 |
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 37 def add(*items) notify_will_change! if items.count > 0 items.flatten.parse_objects.each do |item| collection.push(item) if item.is_a?(Parse::Pointer) end @collection end |
#add!(*items) ⇒ Object
Atomically add a set of Parse::Objects to this collection. This is done by making the API request directly with Parse server; the local object is not updated with changes.
66 67 68 |
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 66 def add!(*items) super(items.flatten.parse_pointers) end |
#add_unique!(*items) ⇒ Object
Atomically add a set of Parse::Objects to this collection for those not already in the collection. This is done by making the API request directly with Parse server; the local object is not updated with changes.
76 77 78 |
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 76 def add_unique!(*items) super(items.flatten.parse_pointers) end |
#as_json(opts = nil) ⇒ Object
Encode the collection as a JSON object of Parse::Pointers.
101 102 103 |
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 101 def as_json(opts = nil) parse_pointers.as_json(opts) end |
#fetch ⇒ Object
Fetch the set of pointer objects in this collection.
96 97 98 |
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 96 def fetch collection.fetch_objects end |
#fetch! ⇒ Object
Force fetch the set of pointer objects in this collection.
90 91 92 |
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 90 def fetch! collection.fetch_objects! end |
#parse_pointers ⇒ Array<Parse::Pointer>
Returns an array of pointers representing this collection.
106 107 108 |
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 106 def parse_pointers collection.parse_pointers end |
#remove(parse_object) ⇒ Array<Parse::Object> #remove(parse_objects) ⇒ Array<Parse::Object>
Removes Parse::Objects from the collection.
53 54 55 56 57 58 59 |
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 53 def remove(*items) notify_will_change! if items.count > 0 items.flatten.parse_objects.each do |item| collection.delete item end @collection end |
#remove!(*items) ⇒ Object
Atomically remove a set of Parse::Objects to this collection. This is done by making the API request directly with Parse server; the local object is not updated with changes.
84 85 86 |
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 84 def remove!(*items) super(items.flatten.parse_pointers) end |