Class: Parse::PointerCollectionProxy

Inherits:
CollectionProxy show all
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

RelationCollectionProxy

Instance Attribute Summary collapse

Attributes inherited from CollectionProxy

#delegate, #key, #loaded, #parse_class

Instance Method Summary collapse

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!, #parse_objects, #parse_pointers, #reload!, #reset!, #rollback!, #second, #select, #set_collection!, #to_a, #uniq, #uniq!, #|

Constructor Details

This class inherits a constructor from Parse::CollectionProxy

Instance Attribute Details

#collectionArray<Parse::Object>

Note:

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.


23
24
25
26
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 23

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.

Overloads:

Returns:


36
37
38
39
40
41
42
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 36

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.


65
66
67
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 65

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.


75
76
77
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 75

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.


100
101
102
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 100

def as_json(opts = nil)
  parse_pointers.as_json(opts)
end

#fetchObject

Fetch the set of pointer objects in this collection.


95
96
97
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 95

def fetch
  collection.fetch_objects
end

#fetch!Object

Force fetch the set of pointer objects in this collection.


89
90
91
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 89

def fetch!
  collection.fetch_objects!
end

#remove(parse_object) ⇒ Array<Parse::Object> #remove(parse_objects) ⇒ Array<Parse::Object>

Removes Parse::Objects from the collection.

Overloads:

Returns:


52
53
54
55
56
57
58
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 52

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.


83
84
85
# File 'lib/parse/model/associations/pointer_collection_proxy.rb', line 83

def remove!(*items)
  super(items.flatten.parse_pointers)
end