Class: Array
- Inherits:
- Object
- Object
- Array
- Defined in:
- lib/parse/model/pointer.rb,
lib/parse/client/batch.rb,
lib/parse/model/object.rb,
lib/parse/model/core/fetching.rb
Overview
extensions
Instance Method Summary collapse
- #destroy ⇒ Parse::BatchOperation
Submit a batch request for deleting a set of Parse::Objects.
- #fetch_objects(lookup = :parallel) ⇒ Array<Parse::Object>
Fetches all the objects in the array that are in Pointer state.
- #fetch_objects!(lookup = :parallel) ⇒ Array<Parse::Object>
Fetches all the objects in the array even if they are not in a Pointer state.
- #objectIds ⇒ Array<String>
This method maps all the ids (String) of all Parse::Objects in the array.
- #parse_ids ⇒ Array<String>
An array of objectIds for all objects that are Parse::Objects.
- #parse_objects(className = nil) ⇒ Array<Parse::Object>
This helper method selects or converts all objects in an array that are either inherit from Parse::Pointer or are a JSON Parse hash.
- #parse_pointers(table = nil) ⇒ Array<Parse::Pointer>
Convert all potential objects in the array to a list of Parse::Pointer instances.
- #save(merge: true, force: false) ⇒ Parse::BatchOperation
Submit a batch request for deleting a set of Parse::Objects.
- #threaded_each(threads = 2) { ... } ⇒ self
Perform a threaded each iteration on a set of array items.
- #threaded_map(threads = 2) { ... } ⇒ Array
Perform a threaded map operation on a set of array items.
- #valid_parse_objects ⇒ Array<Parse::Object,Parse::Pointer>
Filter all objects in the array that do not inherit from Parse::Pointer or Parse::Object.
Instance Method Details
#destroy ⇒ Parse::BatchOperation
Submit a batch request for deleting a set of Parse::Objects.
154 155 156 157 158 159 160 161 162 163 | # File 'lib/parse/client/batch.rb', line 154 def destroy batch = Parse::BatchOperation.new each do |o| next unless o.respond_to?(:destroy_request) r = o.destroy_request batch.add(r) unless r.nil? end batch.submit batch end |
#fetch_objects(lookup = :parallel) ⇒ Array<Parse::Object>
Fetches all the objects in the array that are in Pointer state.
98 99 100 101 102 103 | # File 'lib/parse/model/core/fetching.rb', line 98 def fetch_objects(lookup = :parallel) items = valid_parse_objects lookup == :parallel ? items.threaded_each(2, &:fetch) : items.each(&:fetch) #self.replace items self end |
#fetch_objects!(lookup = :parallel) ⇒ Array<Parse::Object>
Fetches all the objects in the array even if they are not in a Pointer state.
84 85 86 87 88 89 90 | # File 'lib/parse/model/core/fetching.rb', line 84 def fetch_objects!(lookup = :parallel) # this gets all valid parse objects from the array items = valid_parse_objects lookup == :parallel ? items.threaded_each(2, &:fetch!) : items.each(&:fetch!) #self.replace items self #return for chaining. end |
#objectIds ⇒ Array<String>
This method maps all the ids (String) of all Parse::Objects in the array.
204 205 206 | # File 'lib/parse/model/pointer.rb', line 204 def objectIds map { |m| m.is_a?(Parse::Pointer) ? m.id : nil }.compact end |
#parse_ids ⇒ Array<String>
Returns an array of objectIds for all objects that are Parse::Objects.
560 561 562 | # File 'lib/parse/model/object.rb', line 560 def parse_ids parse_objects.map(&:id) end |
#parse_objects(className = nil) ⇒ Array<Parse::Object>
This helper method selects or converts all objects in an array that are either inherit from Parse::Pointer or are a JSON Parse hash. If it is a hash, a Pare::Object will be built from it if it constains the proper fields. Non-convertible objects will be removed. If the className is not contained or known, you can pass a table name as an argument
548 549 550 551 552 553 554 555 556 557 | # File 'lib/parse/model/object.rb', line 548 def parse_objects(className = nil) f = Parse::Model::KEY_CLASS_NAME map do |m| next m if m.is_a?(Parse::Pointer) if m.is_a?(Hash) && (m[f] || m[:className] || className) next Parse::Object.build m, (m[f] || m[:className] || className) end nil end.compact end |
#parse_pointers(table = nil) ⇒ Array<Parse::Pointer>
Convert all potential objects in the array to a list of Parse::Pointer instances. The array can contain a mixture of objects types including JSON Parse-like hashes.
218 219 220 221 222 223 224 225 226 227 228 229 230 | # File 'lib/parse/model/pointer.rb', line 218 def parse_pointers(table = nil) self.map do |m| #if its an exact Parse::Pointer if m.is_a?(Parse::Pointer) || m.respond_to?(:pointer) next m.pointer elsif m.is_a?(Hash) && m[Parse::Model::KEY_CLASS_NAME] && m[Parse::Model::OBJECT_ID] next Parse::Pointer.new m[Parse::Model::KEY_CLASS_NAME], m[Parse::Model::OBJECT_ID] elsif m.is_a?(Hash) && m[:className] && m[:objectId] next Parse::Pointer.new m[:className], m[:objectId] end nil end.compact end |
#save(merge: true, force: false) ⇒ Parse::BatchOperation
The objects of the array to be saved do not all have to be of the same collection.
Submit a batch request for deleting a set of Parse::Objects. Batch requests are supported implicitly and intelligently through an extension of array. When an array of Parse::Object subclasses is saved, Parse-Stack will batch all possible save operations for the objects in the array that have changed. It will also batch save 50 at a time until all items in the array are saved. Note: Parse does not allow batch saving Parse::User objects.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | # File 'lib/parse/client/batch.rb', line 187 def save(merge: true, force: false) batch = Parse::BatchOperation.new objects = {} each do |o| next unless o.is_a?(Parse::Object) objects[o.object_id] = o batch.add o.change_requests(force) end if merge == false batch.submit return batch end #rebind updates batch.submit do |request, response| next unless request.tag.present? && response.present? && response.success? o = objects[request.tag] next unless o.is_a?(Parse::Object) result = response.result o.id = result["objectId"] if o.id.blank? o.set_attributes!(result) o.clear_changes! end batch end |
#threaded_each(threads = 2) { ... } ⇒ self
Perform a threaded each iteration on a set of array items.
64 65 66 | # File 'lib/parse/model/core/fetching.rb', line 64 def threaded_each(threads = 2, &block) Parallel.each(self, { in_threads: threads }, &block) end |
#threaded_map(threads = 2) { ... } ⇒ Array
Perform a threaded map operation on a set of array items.
74 75 76 | # File 'lib/parse/model/core/fetching.rb', line 74 def threaded_map(threads = 2, &block) Parallel.map(self, { in_threads: threads }, &block) end |
#valid_parse_objects ⇒ Array<Parse::Object,Parse::Pointer>
Filter all objects in the array that do not inherit from Parse::Pointer or Parse::Object.
211 212 213 | # File 'lib/parse/model/pointer.rb', line 211 def valid_parse_objects select { |s| s.is_a?(Parse::Pointer) } end |