Skip to content

Commit 946c311

Browse files
hspindellapersaud
authored andcommitted
Replaces deprecated Proc.new usage
“warning: Capturing the given block using Proc.new is deprecated; use `&block` instead”
1 parent 23bf69c commit 946c311

File tree

9 files changed

+42
-43
lines changed

9 files changed

+42
-43
lines changed

lib/parse/client.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ def client(conn = :default)
202202
# @see Parse::Middleware::Caching
203203
# @see Parse::Middleware::Authentication
204204
# @see Parse::Protocol
205-
def setup(opts = {})
206-
@clients[:default] = self.new(opts, &Proc.new)
205+
def setup(opts = {}, &block)
206+
@clients[:default] = self.new(opts, &block)
207207
end
208208
end
209209

@@ -579,9 +579,9 @@ def client
579579
# @yield (see Parse::Client.setup)
580580
# @return (see Parse::Client.setup)
581581
# @see Parse::Client.setup
582-
def self.setup(opts = {})
582+
def self.setup(opts = {}, &block)
583583
if block_given?
584-
Parse::Client.new(opts, &Proc.new)
584+
Parse::Client.new(opts, &block)
585585
else
586586
Parse::Client.new(opts)
587587
end

lib/parse/client/batch.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ def change_requests
8585
end
8686

8787
# @return [Array]
88-
def each
88+
def each(&block)
8989
return enum_for(:each) unless block_given?
90-
@requests.each(&Proc.new)
90+
@requests.each(&block)
9191
end
9292

9393
# @return [Hash] a formatted payload for the batch request.
@@ -125,15 +125,15 @@ def error?
125125
# @param segment [Integer] the number of requests to send in each batch. Default 50.
126126
# @return [Array<Parse::Response>] the corresponding set of responses for
127127
# each request in the batch.
128-
def submit(segment = 50)
128+
def submit(segment = 50, &block)
129129
@responses = []
130130
@requests.uniq!(&:signature)
131131
@responses = @requests.each_slice(segment).to_a.threaded_map(2) do |slice|
132132
client.batch_request(BatchOperation.new(slice))
133133
end
134134
@responses.flatten!
135135
#puts "Requests: #{@requests.count} == Response: #{@responses.count}"
136-
@requests.zip(@responses).each(&Proc.new) if block_given?
136+
@requests.zip(@responses).each(&block) if block_given?
137137
@responses
138138
end
139139

lib/parse/client/response.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ def first
156156

157157
# Iterate through each result item.
158158
# @yieldparam [Object] a result entry.
159-
def each
159+
def each(&block)
160160
return enum_for(:each) unless block_given?
161-
results.each(&Proc.new)
161+
results.each(&block)
162162
self
163163
end
164164

lib/parse/model/associations/collection_proxy.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -328,33 +328,33 @@ def notify_will_change!
328328
end
329329

330330
# Alias for Array#each
331-
def each
331+
def each(&block)
332332
return collection.enum_for(:each) unless block_given?
333-
collection.each &Proc.new
333+
collection.each(&block)
334334
end
335335

336336
# Alias for Array#map
337-
def map
337+
def map(&block)
338338
return collection.enum_for(:map) unless block_given?
339-
collection.map &Proc.new
339+
collection.map(&block)
340340
end
341341

342342
# Alias for Array#select
343-
def select
343+
def select(&block)
344344
return collection.enum_for(:select) unless block_given?
345-
collection.select &Proc.new
345+
collection.select(&block)
346346
end
347347

348348
# Alias for Array#uniq
349-
def uniq
350-
return collection.uniq(&Proc.new) if block_given?
349+
def uniq(&block)
350+
return collection.uniq(&block) if block_given?
351351
return collection.uniq
352352
end
353353

354354
# Alias for Array#uniq!
355-
def uniq!
355+
def uniq!(&block)
356356
notify_will_change!
357-
return collection.uniq!(&Proc.new) if block_given?
357+
return collection.uniq!(&block) if block_given?
358358
return collection.uniq!
359359
end
360360

lib/parse/model/associations/relation_collection_proxy.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ def initialize(collection = nil, delegate: nil, key: nil, parse_class: nil)
5353

5454
# You can get items within the collection relation filtered by a specific set
5555
# of query constraints.
56-
def all(constraints = {})
56+
def all(constraints = {}, &block)
5757
q = query({ limit: :max }.merge(constraints))
5858
if block_given?
5959
# if we have a query, then use the Proc with it (more efficient)
60-
return q.present? ? q.results(&Proc.new) : collection.each(&Proc.new)
60+
return q.present? ? q.results(&block) : collection.each(&block)
6161
end
6262
# if no block given, get all the results
6363
q.present? ? q.results : collection

lib/parse/model/core/actions.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ class Query
1515

1616
# Supporting the `all` class method to be used in scope chaining with queries.
1717
# @!visibility private
18-
def all(expressions = { limit: :max })
18+
def all(expressions = { limit: :max }, &block)
1919
conditions(expressions)
20-
return results(&Proc.new) if block_given?
20+
return results(&block) if block_given?
2121
results
2222
end
2323

@@ -35,15 +35,15 @@ def first_or_create(query_attrs = {}, resource_attrs = {})
3535

3636
# Supporting the `save_all` method to be used in scope chaining with queries.
3737
# @!visibility private
38-
def save_all(expressions = {})
38+
def save_all(expressions = {}, &block)
3939
conditions(expressions)
4040
klass = Parse::Model.find_class self.table
4141
if klass.blank?
4242
raise ArgumentError, "Parse model with class name #{self.table} is not registered."
4343
end
4444
hash_constraints = constraints(true)
4545

46-
klass.save_all(hash_constraints, &Proc.new) if block_given?
46+
klass.save_all(hash_constraints, &block) if block_given?
4747
klass.save_all(hash_constraints)
4848
end
4949
end

lib/parse/model/core/querying.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ def each(constraints = {}, &block)
207207
# by the server.
208208
# @return [Array<Parse::Object>] an array of matching objects. If a block is passed,
209209
# an empty array is returned.
210-
def all(constraints = { limit: :max })
210+
def all(constraints = { limit: :max }, &block)
211211
constraints = constraints.reverse_merge({ limit: :max })
212212
prepared_query = query(constraints)
213-
return prepared_query.results(&Proc.new) if block_given?
213+
return prepared_query.results(&block) if block_given?
214214
prepared_query.results
215215
end
216216

lib/parse/query.rb

+13-13
Original file line numberDiff line numberDiff line change
@@ -662,25 +662,25 @@ def count
662662
# @yield a block yield for each object in the result
663663
# @return [Array]
664664
# @see Array#each
665-
def each
665+
def each(&block)
666666
return results.enum_for(:each) unless block_given? # Sparkling magic!
667-
results.each(&Proc.new)
667+
results.each(&block)
668668
end
669669

670670
# @yield a block yield for each object in the result
671671
# @return [Array]
672672
# @see Array#map
673-
def map
673+
def map(&block)
674674
return results.enum_for(:map) unless block_given? # Sparkling magic!
675-
results.map(&Proc.new)
675+
results.map(&block)
676676
end
677677

678678
# @yield a block yield for each object in the result
679679
# @return [Array]
680680
# @see Array#select
681-
def select
681+
def select(&block)
682682
return results.enum_for(:select) unless block_given? # Sparkling magic!
683-
results.select(&Proc.new)
683+
results.select(&block)
684684
end
685685

686686
# @return [Array]
@@ -700,7 +700,7 @@ def first(limit = 1)
700700
# max_results is used to iterate through as many API requests as possible using
701701
# :skip and :limit paramter.
702702
# @!visibility private
703-
def max_results(raw: false, on_batch: nil, discard_results: false)
703+
def max_results(raw: false, on_batch: nil, discard_results: false, &block)
704704
compiled_query = compile
705705
batch_size = 1_000
706706
results = []
@@ -725,7 +725,7 @@ def max_results(raw: false, on_batch: nil, discard_results: false)
725725
items = decode(items) unless raw
726726
# if a block is provided, we do not keep the results after processing.
727727
if block_given?
728-
items.each(&Proc.new)
728+
items.each(&block)
729729
else
730730
# concat results unless discard_results is true
731731
results += items unless discard_results
@@ -796,15 +796,15 @@ def fetch!(compiled_query)
796796
# @yield a block to iterate for each object that matched the query.
797797
# @return [Array<Hash>] if raw is set to true, a set of Parse JSON hashes.
798798
# @return [Array<Parse::Object>] if raw is set to false, a list of matching Parse::Object subclasses.
799-
def results(raw: false)
799+
def results(raw: false, &block)
800800
if @results.nil?
801801
if block_given?
802-
max_results(raw: raw, &Proc.new)
802+
max_results(raw: raw, &block)
803803
elsif @limit.is_a?(Numeric)
804804
response = fetch!(compile)
805805
return [] if response.error?
806806
items = raw ? response.results : decode(response.results)
807-
return items.each(&Proc.new) if block_given?
807+
return items.each(&block) if block_given?
808808
@results = items
809809
else
810810
@results = max_results(raw: raw)
@@ -822,9 +822,9 @@ def results(raw: false)
822822
# @return [Array<Hash>] if raw is set to true, a set of Parse JSON hashes.
823823
# @return [Array<Parse::Object>] if raw is set to false, a list of matching Parse::Object subclasses.
824824
# @see #results
825-
def all(expressions = { limit: :max })
825+
def all(expressions = { limit: :max }, &block)
826826
conditions(expressions)
827-
return results(&Proc.new) if block_given?
827+
return results(&block) if block_given?
828828
results
829829
end
830830

lib/parse/webhooks.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,12 @@ def routes
125125
# name to register with Parse server.
126126
# @yield the block that will handle of the webhook trigger or function.
127127
# @return (see routes)
128-
def route(type, className, block = nil)
128+
def route(type, className, &block)
129129
type = type.to_s.underscore.to_sym #support camelcase
130130
if type != :function && className.respond_to?(:parse_class)
131131
className = className.parse_class
132132
end
133133
className = className.to_s
134-
block = Proc.new if block_given?
135134
if routes[type].nil? || block.respond_to?(:call) == false
136135
raise ArgumentError, "Invalid Webhook registration trigger #{type} #{className}"
137136
end

0 commit comments

Comments
 (0)