parse-stack 1.7.3 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +36 -0
- data/.solargraph.yml +23 -0
- data/.travis.yml +6 -3
- data/Changes.md +84 -22
- data/Gemfile +14 -12
- data/Gemfile.lock +110 -60
- data/README.md +67 -24
- data/Rakefile +14 -14
- data/bin/parse-console +1 -0
- data/lib/parse/api/aggregate.rb +59 -0
- data/lib/parse/api/all.rb +2 -1
- data/lib/parse/api/analytics.rb +0 -3
- data/lib/parse/api/batch.rb +3 -5
- data/lib/parse/api/cloud_functions.rb +0 -3
- data/lib/parse/api/config.rb +0 -4
- data/lib/parse/api/files.rb +3 -7
- data/lib/parse/api/hooks.rb +4 -8
- data/lib/parse/api/objects.rb +9 -14
- data/lib/parse/api/push.rb +0 -4
- data/lib/parse/api/schema.rb +2 -6
- data/lib/parse/api/server.rb +4 -7
- data/lib/parse/api/sessions.rb +2 -5
- data/lib/parse/api/users.rb +9 -14
- data/lib/parse/client.rb +55 -50
- data/lib/parse/client/authentication.rb +29 -33
- data/lib/parse/client/batch.rb +8 -11
- data/lib/parse/client/body_builder.rb +19 -20
- data/lib/parse/client/caching.rb +23 -28
- data/lib/parse/client/protocol.rb +11 -12
- data/lib/parse/client/request.rb +4 -6
- data/lib/parse/client/response.rb +5 -7
- data/lib/parse/model/acl.rb +14 -12
- data/lib/parse/model/associations/belongs_to.rb +19 -24
- data/lib/parse/model/associations/collection_proxy.rb +328 -317
- data/lib/parse/model/associations/has_many.rb +22 -27
- data/lib/parse/model/associations/has_one.rb +7 -12
- data/lib/parse/model/associations/pointer_collection_proxy.rb +5 -13
- data/lib/parse/model/associations/relation_collection_proxy.rb +5 -9
- data/lib/parse/model/bytes.rb +8 -10
- data/lib/parse/model/classes/installation.rb +2 -4
- data/lib/parse/model/classes/product.rb +2 -5
- data/lib/parse/model/classes/role.rb +3 -5
- data/lib/parse/model/classes/session.rb +2 -5
- data/lib/parse/model/classes/user.rb +21 -17
- data/lib/parse/model/core/actions.rb +31 -46
- data/lib/parse/model/core/builder.rb +6 -6
- data/lib/parse/model/core/errors.rb +0 -1
- data/lib/parse/model/core/fetching.rb +45 -50
- data/lib/parse/model/core/properties.rb +53 -68
- data/lib/parse/model/core/querying.rb +292 -282
- data/lib/parse/model/core/schema.rb +89 -92
- data/lib/parse/model/date.rb +16 -23
- data/lib/parse/model/file.rb +171 -174
- data/lib/parse/model/geopoint.rb +12 -16
- data/lib/parse/model/model.rb +31 -37
- data/lib/parse/model/object.rb +58 -70
- data/lib/parse/model/pointer.rb +177 -176
- data/lib/parse/model/push.rb +8 -10
- data/lib/parse/model/shortnames.rb +1 -2
- data/lib/parse/model/time_zone.rb +3 -5
- data/lib/parse/query.rb +70 -37
- data/lib/parse/query/constraint.rb +4 -6
- data/lib/parse/query/constraints.rb +62 -20
- data/lib/parse/query/operation.rb +8 -11
- data/lib/parse/query/ordering.rb +45 -49
- data/lib/parse/stack.rb +15 -11
- data/lib/parse/stack/generators/rails.rb +28 -30
- data/lib/parse/stack/generators/templates/model.erb +5 -6
- data/lib/parse/stack/generators/templates/model_installation.rb +0 -1
- data/lib/parse/stack/generators/templates/model_role.rb +0 -1
- data/lib/parse/stack/generators/templates/model_session.rb +0 -1
- data/lib/parse/stack/generators/templates/model_user.rb +0 -1
- data/lib/parse/stack/generators/templates/parse.rb +9 -9
- data/lib/parse/stack/generators/templates/webhooks.rb +1 -2
- data/lib/parse/stack/railtie.rb +2 -4
- data/lib/parse/stack/tasks.rb +70 -86
- data/lib/parse/stack/version.rb +1 -1
- data/lib/parse/webhooks.rb +19 -26
- data/lib/parse/webhooks/payload.rb +26 -28
- data/lib/parse/webhooks/registration.rb +23 -31
- data/parse-stack.gemspec +28 -28
- data/parse-stack.png +0 -0
- metadata +27 -25
- data/.github/parse-ruby-sdk.png +0 -0
@@ -1,23 +1,30 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require_relative
|
4
|
+
require_relative "../object"
|
5
|
+
|
5
6
|
module Parse
|
6
7
|
class Error
|
7
8
|
# 200 Error code indicating that the username is missing or empty.
|
8
|
-
class UsernameMissingError < Error; end
|
9
|
+
class UsernameMissingError < Error; end
|
10
|
+
|
9
11
|
# 201 Error code indicating that the password is missing or empty.
|
10
|
-
class PasswordMissingError < Error; end
|
12
|
+
class PasswordMissingError < Error; end
|
13
|
+
|
11
14
|
# Error code 202: indicating that the username has already been taken.
|
12
|
-
class UsernameTakenError < Error; end
|
15
|
+
class UsernameTakenError < Error; end
|
16
|
+
|
13
17
|
# 203 Error code indicating that the email has already been taken.
|
14
|
-
class EmailTakenError < Error; end
|
18
|
+
class EmailTakenError < Error; end
|
19
|
+
|
15
20
|
# 204 Error code indicating that the email is missing, but must be specified.
|
16
|
-
class EmailMissing < Error; end
|
21
|
+
class EmailMissing < Error; end
|
22
|
+
|
17
23
|
# 205 Error code indicating that a user with the specified email was not found.
|
18
|
-
class EmailNotFound < Error; end
|
24
|
+
class EmailNotFound < Error; end
|
25
|
+
|
19
26
|
# 125 Error code indicating that the email address was invalid.
|
20
|
-
class InvalidEmailAddress < Error; end
|
27
|
+
class InvalidEmailAddress < Error; end
|
21
28
|
end
|
22
29
|
|
23
30
|
# The main class representing the _User table in Parse. A user can either be signed up or anonymous.
|
@@ -137,7 +144,6 @@ module Parse
|
|
137
144
|
#
|
138
145
|
# @see Parse::Object
|
139
146
|
class User < Parse::Object
|
140
|
-
|
141
147
|
parse_class Parse::Model::CLASS_USER
|
142
148
|
# @return [String] The session token if this user is logged in.
|
143
149
|
attr_accessor :session_token
|
@@ -177,7 +183,7 @@ module Parse
|
|
177
183
|
|
178
184
|
before_save do
|
179
185
|
# You cannot specify user ACLs.
|
180
|
-
self.clear_attribute_change!(:acl)
|
186
|
+
self.clear_attribute_change!([:acl])
|
181
187
|
end
|
182
188
|
|
183
189
|
# @return [Boolean] true if this user is anonymous.
|
@@ -189,7 +195,7 @@ module Parse
|
|
189
195
|
# @see #anonymous?
|
190
196
|
# @return [String] The anonymous identifier for this anonymous user.
|
191
197
|
def anonymous_id
|
192
|
-
auth_data[
|
198
|
+
auth_data["anonymous"]["id"] if auth_data.present? && auth_data["anonymous"].is_a?(Hash)
|
193
199
|
end
|
194
200
|
|
195
201
|
# Adds the third-party authentication data to for a given service.
|
@@ -212,12 +218,12 @@ module Parse
|
|
212
218
|
apply_attributes!(response.result)
|
213
219
|
end
|
214
220
|
|
215
|
-
|
216
221
|
# @!visibility private
|
217
222
|
# So that apply_attributes! works with session_token for login
|
218
223
|
def session_token_set_attribute!(token, track = false)
|
219
224
|
@session_token = token.to_s
|
220
225
|
end
|
226
|
+
|
221
227
|
alias_method :sessionToken_set_attribute!, :session_token_set_attribute!
|
222
228
|
|
223
229
|
# @return [Boolean] true if this user has a session token.
|
@@ -341,7 +347,7 @@ module Parse
|
|
341
347
|
when Parse::Response::ERROR_EMAIL_TAKEN
|
342
348
|
raise Parse::Error::EmailTakenError, response
|
343
349
|
end
|
344
|
-
raise
|
350
|
+
raise Parse::Client::ResponseError, response
|
345
351
|
end
|
346
352
|
|
347
353
|
# Automatically and implicitly signup a user if it did not already exists and
|
@@ -353,7 +359,7 @@ module Parse
|
|
353
359
|
# @return [User] a logged in user, or nil.
|
354
360
|
# @see User.create
|
355
361
|
def self.autologin_service(service_name, auth_data, body: {})
|
356
|
-
body = body.merge({authData: {service_name => auth_data} })
|
362
|
+
body = body.merge({ authData: { service_name => auth_data } })
|
357
363
|
self.create(body)
|
358
364
|
end
|
359
365
|
|
@@ -364,7 +370,7 @@ module Parse
|
|
364
370
|
# This method will raise all the exceptions from the similar `create` method.
|
365
371
|
# @see User.create
|
366
372
|
def self.signup(username, password, email = nil, body: {})
|
367
|
-
body = body.merge({username: username, password: password })
|
373
|
+
body = body.merge({ username: username, password: password })
|
368
374
|
body[:email] = email if email.present?
|
369
375
|
self.create(body)
|
370
376
|
end
|
@@ -427,7 +433,5 @@ module Parse
|
|
427
433
|
end
|
428
434
|
@session_token
|
429
435
|
end
|
430
|
-
|
431
436
|
end
|
432
|
-
|
433
437
|
end
|
@@ -1,24 +1,21 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
|
4
|
+
require "active_model"
|
5
|
+
require "active_support"
|
6
|
+
require "active_support/inflector"
|
7
|
+
require "active_support/core_ext"
|
8
|
+
require "time"
|
9
|
+
require "parallel"
|
10
|
+
require_relative "../../client/request"
|
11
|
+
require_relative "fetching"
|
13
12
|
|
14
13
|
module Parse
|
15
|
-
|
16
14
|
class Query
|
17
15
|
|
18
|
-
|
19
16
|
# Supporting the `all` class method to be used in scope chaining with queries.
|
20
17
|
# @!visibility private
|
21
|
-
def all(expressions = {limit: :max})
|
18
|
+
def all(expressions = { limit: :max })
|
22
19
|
conditions(expressions)
|
23
20
|
return results(&Proc.new) if block_given?
|
24
21
|
results
|
@@ -49,7 +46,6 @@ module Parse
|
|
49
46
|
klass.save_all(hash_constraints, &Proc.new) if block_given?
|
50
47
|
klass.save_all(hash_constraints)
|
51
48
|
end
|
52
|
-
|
53
49
|
end
|
54
50
|
|
55
51
|
# A Parse::RelationAction is special operation that adds one object to a relational
|
@@ -80,16 +76,12 @@ module Parse
|
|
80
76
|
|
81
77
|
# @return [Hash] a hash representing a relation operation.
|
82
78
|
def as_json(*args)
|
83
|
-
{ @key =>
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
}
|
88
|
-
}.as_json
|
79
|
+
{ @key => {
|
80
|
+
"__op" => (@polarity == true ? ADD : REMOVE),
|
81
|
+
"objects" => objects.parse_pointers,
|
82
|
+
} }.as_json
|
89
83
|
end
|
90
|
-
|
91
84
|
end
|
92
|
-
|
93
85
|
end
|
94
86
|
|
95
87
|
# This module is mainly all the basic orm operations. To support batching actions,
|
@@ -132,7 +124,7 @@ module Parse
|
|
132
124
|
# @example
|
133
125
|
# # globally across all models
|
134
126
|
# Parse::Model.raise_on_save_failure = true
|
135
|
-
|
127
|
+
# Song.raise_on_save_failure = true # per-model
|
136
128
|
#
|
137
129
|
# # or per-instance raise on failure
|
138
130
|
# song.save!
|
@@ -156,7 +148,6 @@ module Parse
|
|
156
148
|
# @param resource_attrs [Hash] a set of attribute values to be applied if an object was not found.
|
157
149
|
# @return [Parse::Object] a Parse::Object, whether found by the query or newly created.
|
158
150
|
def first_or_create(query_attrs = {}, resource_attrs = {})
|
159
|
-
|
160
151
|
query_attrs = query_attrs.symbolize_keys
|
161
152
|
resource_attrs = resource_attrs.symbolize_keys
|
162
153
|
obj = query(query_attrs).first
|
@@ -205,7 +196,7 @@ module Parse
|
|
205
196
|
def save_all(constraints = {})
|
206
197
|
invalid_constraints = constraints.keys.any? do |k|
|
207
198
|
(k == :updated_at || k == :updatedAt) ||
|
208
|
-
(
|
199
|
+
(k.is_a?(Parse::Operation) && (k.operand == :updated_at || k.operand == :updatedAt))
|
209
200
|
end
|
210
201
|
if invalid_constraints
|
211
202
|
raise ArgumentError,
|
@@ -267,14 +258,12 @@ module Parse
|
|
267
258
|
warn "[#{self}.save_all] Reached anchor date #{anchor_date} < #{cursor.updated_at}"
|
268
259
|
break cursor
|
269
260
|
end
|
270
|
-
|
271
261
|
end
|
272
262
|
|
273
263
|
has_errors ||= batch.error?
|
274
264
|
end
|
275
265
|
not has_errors
|
276
266
|
end
|
277
|
-
|
278
267
|
end # ClassMethods
|
279
268
|
|
280
269
|
# Perform an atomic operation on this field. This operation is done on the
|
@@ -295,7 +284,7 @@ module Parse
|
|
295
284
|
op_hash = { field => op_hash }.as_json
|
296
285
|
end
|
297
286
|
|
298
|
-
response = client.update_object(parse_class, id, op_hash, session_token: _session_token
|
287
|
+
response = client.update_object(parse_class, id, op_hash, session_token: _session_token)
|
299
288
|
if response.error?
|
300
289
|
puts "[#{parse_class}:#{field} Operation] #{response.error}"
|
301
290
|
end
|
@@ -307,7 +296,7 @@ module Parse
|
|
307
296
|
# @param objects [Array] the set of items to add to this field.
|
308
297
|
# @return [Boolean] whether it was successful
|
309
298
|
# @see #operate_field!
|
310
|
-
def op_add!(field,objects)
|
299
|
+
def op_add!(field, objects)
|
311
300
|
operate_field! field, { __op: :Add, objects: objects }
|
312
301
|
end
|
313
302
|
|
@@ -317,7 +306,7 @@ module Parse
|
|
317
306
|
# @param objects [Array] the set of items to add uniquely to this field.
|
318
307
|
# @return [Boolean] whether it was successful
|
319
308
|
# @see #operate_field!
|
320
|
-
def op_add_unique!(field,objects)
|
309
|
+
def op_add_unique!(field, objects)
|
321
310
|
operate_field! field, { __op: :AddUnique, objects: objects }
|
322
311
|
end
|
323
312
|
|
@@ -377,7 +366,7 @@ module Parse
|
|
377
366
|
def destroy_request
|
378
367
|
return nil unless @id.present?
|
379
368
|
uri = self.uri_path
|
380
|
-
r = Request.new(
|
369
|
+
r = Request.new(:delete, uri)
|
381
370
|
r.tag = object_id
|
382
371
|
r
|
383
372
|
end
|
@@ -401,7 +390,7 @@ module Parse
|
|
401
390
|
if attribute_changes? || force
|
402
391
|
# if it's new, then we should call :post for creating the object.
|
403
392
|
method = new? ? :post : :put
|
404
|
-
r = Request.new(
|
393
|
+
r = Request.new(method, uri, body: attribute_updates)
|
405
394
|
r.tag = object_id
|
406
395
|
requests << r
|
407
396
|
end
|
@@ -411,7 +400,7 @@ module Parse
|
|
411
400
|
if @id.present? && relation_changes?
|
412
401
|
relation_change_operations.each do |ops|
|
413
402
|
next if ops.empty?
|
414
|
-
r = Request.new(
|
403
|
+
r = Request.new(:put, uri, body: ops)
|
415
404
|
r.tag = object_id
|
416
405
|
requests << r
|
417
406
|
end
|
@@ -515,7 +504,7 @@ module Parse
|
|
515
504
|
if relation_changes?
|
516
505
|
# get the list of changed keys
|
517
506
|
changed_attribute_keys = changed - relations.keys.map(&:to_s)
|
518
|
-
clear_attribute_changes(
|
507
|
+
clear_attribute_changes(changed_attribute_keys)
|
519
508
|
success = update_relations
|
520
509
|
if success
|
521
510
|
changes_applied!
|
@@ -528,7 +517,6 @@ module Parse
|
|
528
517
|
elsif self.class.raise_on_save_failure || autoraise.present?
|
529
518
|
raise Parse::RecordNotSaved.new(self), "Failed to create or save attributes. #{self.parse_class} was not saved."
|
530
519
|
end
|
531
|
-
|
532
520
|
end #callbacks
|
533
521
|
@_session_token = nil
|
534
522
|
success
|
@@ -543,7 +531,6 @@ module Parse
|
|
543
531
|
save(autoraise: true, session: session)
|
544
532
|
end
|
545
533
|
|
546
|
-
|
547
534
|
# Delete this record from the Parse collection. Only valid if this object has an `id`.
|
548
535
|
# This will run all the `destroy` callbacks.
|
549
536
|
# @param session [String] a session token if you want to apply ACLs for a user in this operation.
|
@@ -577,12 +564,13 @@ module Parse
|
|
577
564
|
def changes_payload
|
578
565
|
h = attribute_updates
|
579
566
|
if relation_changes?
|
580
|
-
r =
|
567
|
+
r = relation_change_operations.select { |s| s.present? }.first
|
581
568
|
h.merge!(r) if r.present?
|
582
569
|
end
|
583
570
|
#h.merge!(className: parse_class) unless h.empty?
|
584
571
|
h.as_json
|
585
572
|
end
|
573
|
+
|
586
574
|
alias_method :update_payload, :changes_payload
|
587
575
|
|
588
576
|
# Generates an array with two entries for addition and removal operations. The first entry
|
@@ -592,12 +580,12 @@ module Parse
|
|
592
580
|
# @return [Array] an array with two hashes; the first is a hash of all the addition operations and
|
593
581
|
# the second hash, all the remove operations.
|
594
582
|
def relation_change_operations
|
595
|
-
return [{},{}] unless relation_changes?
|
583
|
+
return [{}, {}] unless relation_changes?
|
596
584
|
|
597
585
|
additions = []
|
598
586
|
removals = []
|
599
587
|
# go through all the additions of a collection and generate an action to add.
|
600
|
-
relation_updates.each do |field,collection|
|
588
|
+
relation_updates.each do |field, collection|
|
601
589
|
if collection.additions.count > 0
|
602
590
|
additions.push Parse::RelationAction.new(field, objects: collection.additions, polarity: true)
|
603
591
|
end
|
@@ -607,8 +595,8 @@ module Parse
|
|
607
595
|
end
|
608
596
|
end
|
609
597
|
# merge all additions and removals into one large hash
|
610
|
-
additions = additions.reduce({}) { |m,v| m.merge! v.as_json }
|
611
|
-
removals = removals.reduce({}) { |m,v| m.merge! v.as_json }
|
598
|
+
additions = additions.reduce({}) { |m, v| m.merge! v.as_json }
|
599
|
+
removals = removals.reduce({}) { |m, v| m.merge! v.as_json }
|
612
600
|
[additions, removals]
|
613
601
|
end
|
614
602
|
|
@@ -656,7 +644,7 @@ module Parse
|
|
656
644
|
# @return [Hash]
|
657
645
|
def set_attributes!(hash, dirty_track = false)
|
658
646
|
return unless hash.is_a?(Hash)
|
659
|
-
hash.each do |k,v|
|
647
|
+
hash.each do |k, v|
|
660
648
|
next if k == Parse::Model::OBJECT_ID || k == Parse::Model::ID
|
661
649
|
method = "#{k}_set_attribute!"
|
662
650
|
send(method, v, dirty_track) if respond_to?(method)
|
@@ -667,23 +655,20 @@ module Parse
|
|
667
655
|
# local attributes.
|
668
656
|
def changes_applied!
|
669
657
|
# find all fields that are of type :array
|
670
|
-
fields(:array) do |key,v|
|
658
|
+
fields(:array) do |key, v|
|
671
659
|
proxy = send(key)
|
672
660
|
# clear changes
|
673
661
|
proxy.changes_applied! if proxy.respond_to?(:changes_applied!)
|
674
662
|
end
|
675
663
|
|
676
664
|
# for all relational fields,
|
677
|
-
relations.each do |key,v|
|
665
|
+
relations.each do |key, v|
|
678
666
|
proxy = send(key)
|
679
667
|
# clear changes if they support the method.
|
680
668
|
proxy.changes_applied! if proxy.respond_to?(:changes_applied!)
|
681
669
|
end
|
682
670
|
changes_applied
|
683
671
|
end
|
684
|
-
|
685
|
-
|
686
672
|
end
|
687
673
|
end
|
688
|
-
|
689
674
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require_relative
|
4
|
+
require "active_support"
|
5
|
+
require "active_support/inflector"
|
6
|
+
require "active_support/core_ext"
|
7
|
+
require_relative "../object"
|
8
8
|
|
9
9
|
module Parse
|
10
10
|
# Create all Parse::Object subclasses, including their properties and inferred
|
@@ -60,9 +60,9 @@ module Parse
|
|
60
60
|
|
61
61
|
data_type = type[:type].downcase.to_sym
|
62
62
|
if data_type == :pointer
|
63
|
-
klass.belongs_to key, as: type[:targetClass],
|
63
|
+
klass.belongs_to key, as: type[:targetClass], field: field
|
64
64
|
elsif data_type == :relation
|
65
|
-
klass.has_many key, as: type[:targetClass],
|
65
|
+
klass.has_many key, through: :relation, as: type[:targetClass], field: field
|
66
66
|
else
|
67
67
|
klass.property key, data_type, field: field
|
68
68
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "time"
|
5
|
+
require "parallel"
|
6
6
|
|
7
7
|
module Parse
|
8
8
|
# Combines a set of core functionality for {Parse::Object} and its subclasses.
|
@@ -48,62 +48,57 @@ module Parse
|
|
48
48
|
send :fetch
|
49
49
|
@fetch_lock = false
|
50
50
|
end
|
51
|
-
|
52
51
|
end
|
53
|
-
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
58
|
-
|
59
|
-
|
60
56
|
class Array
|
61
57
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
# Perform a threaded map operation on a set of array items.
|
73
|
-
# @param threads [Integer] the maximum number of threads to spawn
|
74
|
-
# @yield the block for the map iteration.
|
75
|
-
# @return [Array] the resultant array from the map.
|
76
|
-
# @see Array#map
|
77
|
-
# @see https://github.com/grosser/parallel Parallel
|
78
|
-
def threaded_map(threads = 2, &block)
|
79
|
-
Parallel.map(self, {in_threads: threads}, &block)
|
80
|
-
end
|
58
|
+
# Perform a threaded each iteration on a set of array items.
|
59
|
+
# @param threads [Integer] the maximum number of threads to spawn/
|
60
|
+
# @yield the block for the each iteration.
|
61
|
+
# @return [self]
|
62
|
+
# @see Array#each
|
63
|
+
# @see https://github.com/grosser/parallel Parallel
|
64
|
+
def threaded_each(threads = 2, &block)
|
65
|
+
Parallel.each(self, { in_threads: threads }, &block)
|
66
|
+
end
|
81
67
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
lookup == :parallel ? items.threaded_each(2,&:fetch!) : items.each(&:fetch!)
|
92
|
-
#self.replace items
|
93
|
-
self #return for chaining.
|
94
|
-
end
|
68
|
+
# Perform a threaded map operation on a set of array items.
|
69
|
+
# @param threads [Integer] the maximum number of threads to spawn
|
70
|
+
# @yield the block for the map iteration.
|
71
|
+
# @return [Array] the resultant array from the map.
|
72
|
+
# @see Array#map
|
73
|
+
# @see https://github.com/grosser/parallel Parallel
|
74
|
+
def threaded_map(threads = 2, &block)
|
75
|
+
Parallel.map(self, { in_threads: threads }, &block)
|
76
|
+
end
|
95
77
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
78
|
+
# Fetches all the objects in the array even if they are not in a Pointer state.
|
79
|
+
# @param lookup [Symbol] The methodology to use for HTTP requests. Use :parallel
|
80
|
+
# to fetch all objects in parallel HTTP requests. Set to anything else to
|
81
|
+
# perform requests serially.
|
82
|
+
# @return [Array<Parse::Object>] an array of fetched Parse::Objects.
|
83
|
+
# @see Array#fetch_objects
|
84
|
+
def fetch_objects!(lookup = :parallel)
|
85
|
+
# this gets all valid parse objects from the array
|
86
|
+
items = valid_parse_objects
|
87
|
+
lookup == :parallel ? items.threaded_each(2, &:fetch!) : items.each(&:fetch!)
|
88
|
+
#self.replace items
|
89
|
+
self #return for chaining.
|
90
|
+
end
|
108
91
|
|
92
|
+
# Fetches all the objects in the array that are in Pointer state.
|
93
|
+
# @param lookup [Symbol] The methodology to use for HTTP requests. Use :parallel
|
94
|
+
# to fetch all objects in parallel HTTP requests. Set to anything else to
|
95
|
+
# perform requests serially.
|
96
|
+
# @return [Array<Parse::Object>] an array of fetched Parse::Objects.
|
97
|
+
# @see Array#fetch_objects!
|
98
|
+
def fetch_objects(lookup = :parallel)
|
99
|
+
items = valid_parse_objects
|
100
|
+
lookup == :parallel ? items.threaded_each(2, &:fetch) : items.each(&:fetch)
|
101
|
+
#self.replace items
|
102
|
+
self
|
103
|
+
end
|
109
104
|
end
|