From 443b4d937ce5e7a5240e23c28bc5553f5a514857 Mon Sep 17 00:00:00 2001 From: Anthony Persaud Date: Mon, 3 May 2021 17:57:24 -0700 Subject: [PATCH 1/3] Bump 1.10.0 --- Gemfile.lock | 2 +- lib/parse/stack/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6426b4f..c62d170 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - parse-stack (1.9.1) + parse-stack (1.10.0) active_model_serializers (>= 0.9, < 1) activemodel (>= 5, < 7) activesupport (>= 5, < 7) diff --git a/lib/parse/stack/version.rb b/lib/parse/stack/version.rb index 9f9a41a..a1bcb37 100644 --- a/lib/parse/stack/version.rb +++ b/lib/parse/stack/version.rb @@ -6,6 +6,6 @@ module Parse # The Parse Server SDK for Ruby module Stack # The current version. - VERSION = "1.9.1" + VERSION = "1.10.0" end end From 54e2514e269a6d93d2ce7b7d528d22811a6a134d Mon Sep 17 00:00:00 2001 From: Anthony Persaud Date: Mon, 3 May 2021 18:04:43 -0700 Subject: [PATCH 2/3] [#62] Separate positional and keyword arguments for Ruby 3.0 --- lib/parse/api/users.rb | 4 ++-- lib/parse/model/associations/has_many.rb | 2 +- lib/parse/model/classes/session.rb | 2 +- lib/parse/model/classes/user.rb | 2 +- lib/parse/model/core/fetching.rb | 2 +- lib/parse/query.rb | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/parse/api/users.rb b/lib/parse/api/users.rb index bba45d0..295df95 100644 --- a/lib/parse/api/users.rb +++ b/lib/parse/api/users.rb @@ -84,7 +84,7 @@ def update_user(id, body = {}, headers: {}, **opts) # @return [Parse::Response] def set_service_auth_data(id, service_name, auth_data, headers: {}, **opts) body = { authData: { service_name => auth_data } } - update_user(id, body, opts) + update_user(id, body, **opts) end # Delete a {Parse::User} record given an objectId. @@ -143,7 +143,7 @@ def logout(session_token, headers: {}, **opts) def signup(username, password, email = nil, body: {}, **opts) body = body.merge({ username: username, password: password }) body[:email] = email || body[:email] - create_user(body, opts) + create_user(body, **opts) end end # Users end #API diff --git a/lib/parse/model/associations/has_many.rb b/lib/parse/model/associations/has_many.rb index 6d69020..86d1e4d 100644 --- a/lib/parse/model/associations/has_many.rb +++ b/lib/parse/model/associations/has_many.rb @@ -406,7 +406,7 @@ def has_many(key, scope = nil, **opts) opts[:through] ||= :query if opts[:through] == :query - return has_many_queried(key, scope, opts) + return has_many_queried(key, scope, **opts) end # below this is the same diff --git a/lib/parse/model/classes/session.rb b/lib/parse/model/classes/session.rb index 36db1f7..aa5cef8 100644 --- a/lib/parse/model/classes/session.rb +++ b/lib/parse/model/classes/session.rb @@ -68,7 +68,7 @@ class Session < Parse::Object # @param token [String] the session token # @return [Session] the session for this token, otherwise nil. def self.session(token, **opts) - response = client.fetch_session(token, opts) + response = client.fetch_session(token, **opts) if response.success? return Parse::Session.build response.result end diff --git a/lib/parse/model/classes/user.rb b/lib/parse/model/classes/user.rb index 19b3051..a15c437 100644 --- a/lib/parse/model/classes/user.rb +++ b/lib/parse/model/classes/user.rb @@ -417,7 +417,7 @@ def self.session(token, opts = {}) def self.session!(token, opts = {}) # support Parse::Session objects token = token.session_token if token.respond_to?(:session_token) - response = client.current_user(token, opts) + response = client.current_user(token, **opts) response.success? ? Parse::User.build(response.result) : nil end diff --git a/lib/parse/model/core/fetching.rb b/lib/parse/model/core/fetching.rb index 8c69c90..448cc68 100644 --- a/lib/parse/model/core/fetching.rb +++ b/lib/parse/model/core/fetching.rb @@ -15,7 +15,7 @@ module Fetching # @param opts [Hash] a set of options to pass to the client request. # @return [self] the current object, useful for chaining. def fetch!(opts = {}) - response = client.fetch_object(parse_class, id, opts) + response = client.fetch_object(parse_class, id, **opts) if response.error? puts "[Fetch Error] #{response.code}: #{response.error}" end diff --git a/lib/parse/query.rb b/lib/parse/query.rb index c6e8695..d53e52e 100644 --- a/lib/parse/query.rb +++ b/lib/parse/query.rb @@ -635,7 +635,7 @@ def distinct(field) compile_query[:distinct] = Query.format_field(field).to_sym @count = old_count_value # perform aggregation - return client.aggregate_objects(@table, compile_query.as_json, _opts).result + return client.aggregate_objects(@table, compile_query.as_json, **_opts).result else raise ArgumentError, "Invalid field name passed to `distinct`." end @@ -654,7 +654,7 @@ def distinct(field) def count old_value = @count @count = 1 - res = client.find_objects(@table, compile.as_json, _opts).count + res = client.find_objects(@table, compile.as_json, **_opts).count @count = old_value res end @@ -766,7 +766,7 @@ def _opts # @param compiled_query [Hash] the compiled query # @return [Parse::Response] a response for a query request. def fetch!(compiled_query) - response = client.find_objects(@table, compiled_query.as_json, _opts) + response = client.find_objects(@table, compiled_query.as_json, **_opts) if response.error? puts "[ParseQuery] #{response.error}" end From 5841de0802f8383b64591d150f9d3e9003c30b42 Mon Sep 17 00:00:00 2001 From: Henry Spindell Date: Fri, 9 Apr 2021 10:44:16 -0700 Subject: [PATCH 3/3] Replaces deprecated Proc.new usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “warning: Capturing the given block using Proc.new is deprecated; use `&block` instead” --- lib/parse/client.rb | 8 +++--- lib/parse/client/batch.rb | 8 +++--- lib/parse/client/response.rb | 4 +-- .../model/associations/collection_proxy.rb | 20 +++++++------- .../associations/relation_collection_proxy.rb | 4 +-- lib/parse/model/core/actions.rb | 8 +++--- lib/parse/model/core/querying.rb | 4 +-- lib/parse/query.rb | 26 +++++++++---------- lib/parse/webhooks.rb | 3 +-- 9 files changed, 42 insertions(+), 43 deletions(-) diff --git a/lib/parse/client.rb b/lib/parse/client.rb index 167cc9d..4384dab 100644 --- a/lib/parse/client.rb +++ b/lib/parse/client.rb @@ -202,8 +202,8 @@ def client(conn = :default) # @see Parse::Middleware::Caching # @see Parse::Middleware::Authentication # @see Parse::Protocol - def setup(opts = {}) - @clients[:default] = self.new(opts, &Proc.new) + def setup(opts = {}, &block) + @clients[:default] = self.new(opts, &block) end end @@ -579,9 +579,9 @@ def client # @yield (see Parse::Client.setup) # @return (see Parse::Client.setup) # @see Parse::Client.setup - def self.setup(opts = {}) + def self.setup(opts = {}, &block) if block_given? - Parse::Client.new(opts, &Proc.new) + Parse::Client.new(opts, &block) else Parse::Client.new(opts) end diff --git a/lib/parse/client/batch.rb b/lib/parse/client/batch.rb index de696e5..7c04132 100644 --- a/lib/parse/client/batch.rb +++ b/lib/parse/client/batch.rb @@ -85,9 +85,9 @@ def change_requests end # @return [Array] - def each + def each(&block) return enum_for(:each) unless block_given? - @requests.each(&Proc.new) + @requests.each(&block) end # @return [Hash] a formatted payload for the batch request. @@ -125,7 +125,7 @@ def error? # @param segment [Integer] the number of requests to send in each batch. Default 50. # @return [Array] the corresponding set of responses for # each request in the batch. - def submit(segment = 50) + def submit(segment = 50, &block) @responses = [] @requests.uniq!(&:signature) @responses = @requests.each_slice(segment).to_a.threaded_map(2) do |slice| @@ -133,7 +133,7 @@ def submit(segment = 50) end @responses.flatten! #puts "Requests: #{@requests.count} == Response: #{@responses.count}" - @requests.zip(@responses).each(&Proc.new) if block_given? + @requests.zip(@responses).each(&block) if block_given? @responses end diff --git a/lib/parse/client/response.rb b/lib/parse/client/response.rb index 1f6a3ee..161f005 100644 --- a/lib/parse/client/response.rb +++ b/lib/parse/client/response.rb @@ -156,9 +156,9 @@ def first # Iterate through each result item. # @yieldparam [Object] a result entry. - def each + def each(&block) return enum_for(:each) unless block_given? - results.each(&Proc.new) + results.each(&block) self end diff --git a/lib/parse/model/associations/collection_proxy.rb b/lib/parse/model/associations/collection_proxy.rb index 6b56529..561614a 100644 --- a/lib/parse/model/associations/collection_proxy.rb +++ b/lib/parse/model/associations/collection_proxy.rb @@ -328,33 +328,33 @@ def notify_will_change! end # Alias for Array#each - def each + def each(&block) return collection.enum_for(:each) unless block_given? - collection.each &Proc.new + collection.each(&block) end # Alias for Array#map - def map + def map(&block) return collection.enum_for(:map) unless block_given? - collection.map &Proc.new + collection.map(&block) end # Alias for Array#select - def select + def select(&block) return collection.enum_for(:select) unless block_given? - collection.select &Proc.new + collection.select(&block) end # Alias for Array#uniq - def uniq - return collection.uniq(&Proc.new) if block_given? + def uniq(&block) + return collection.uniq(&block) if block_given? return collection.uniq end # Alias for Array#uniq! - def uniq! + def uniq!(&block) notify_will_change! - return collection.uniq!(&Proc.new) if block_given? + return collection.uniq!(&block) if block_given? return collection.uniq! end diff --git a/lib/parse/model/associations/relation_collection_proxy.rb b/lib/parse/model/associations/relation_collection_proxy.rb index 41d31c2..2fb719c 100644 --- a/lib/parse/model/associations/relation_collection_proxy.rb +++ b/lib/parse/model/associations/relation_collection_proxy.rb @@ -53,11 +53,11 @@ def initialize(collection = nil, delegate: nil, key: nil, parse_class: nil) # You can get items within the collection relation filtered by a specific set # of query constraints. - def all(constraints = {}) + def all(constraints = {}, &block) q = query({ limit: :max }.merge(constraints)) if block_given? # if we have a query, then use the Proc with it (more efficient) - return q.present? ? q.results(&Proc.new) : collection.each(&Proc.new) + return q.present? ? q.results(&block) : collection.each(&block) end # if no block given, get all the results q.present? ? q.results : collection diff --git a/lib/parse/model/core/actions.rb b/lib/parse/model/core/actions.rb index 8b62384..6840f96 100644 --- a/lib/parse/model/core/actions.rb +++ b/lib/parse/model/core/actions.rb @@ -15,9 +15,9 @@ class Query # Supporting the `all` class method to be used in scope chaining with queries. # @!visibility private - def all(expressions = { limit: :max }) + def all(expressions = { limit: :max }, &block) conditions(expressions) - return results(&Proc.new) if block_given? + return results(&block) if block_given? results end @@ -35,7 +35,7 @@ def first_or_create(query_attrs = {}, resource_attrs = {}) # Supporting the `save_all` method to be used in scope chaining with queries. # @!visibility private - def save_all(expressions = {}) + def save_all(expressions = {}, &block) conditions(expressions) klass = Parse::Model.find_class self.table if klass.blank? @@ -43,7 +43,7 @@ def save_all(expressions = {}) end hash_constraints = constraints(true) - klass.save_all(hash_constraints, &Proc.new) if block_given? + klass.save_all(hash_constraints, &block) if block_given? klass.save_all(hash_constraints) end end diff --git a/lib/parse/model/core/querying.rb b/lib/parse/model/core/querying.rb index 56598b1..502ff62 100644 --- a/lib/parse/model/core/querying.rb +++ b/lib/parse/model/core/querying.rb @@ -207,10 +207,10 @@ def each(constraints = {}, &block) # by the server. # @return [Array] an array of matching objects. If a block is passed, # an empty array is returned. - def all(constraints = { limit: :max }) + def all(constraints = { limit: :max }, &block) constraints = constraints.reverse_merge({ limit: :max }) prepared_query = query(constraints) - return prepared_query.results(&Proc.new) if block_given? + return prepared_query.results(&block) if block_given? prepared_query.results end diff --git a/lib/parse/query.rb b/lib/parse/query.rb index d53e52e..a27b4cc 100644 --- a/lib/parse/query.rb +++ b/lib/parse/query.rb @@ -662,25 +662,25 @@ def count # @yield a block yield for each object in the result # @return [Array] # @see Array#each - def each + def each(&block) return results.enum_for(:each) unless block_given? # Sparkling magic! - results.each(&Proc.new) + results.each(&block) end # @yield a block yield for each object in the result # @return [Array] # @see Array#map - def map + def map(&block) return results.enum_for(:map) unless block_given? # Sparkling magic! - results.map(&Proc.new) + results.map(&block) end # @yield a block yield for each object in the result # @return [Array] # @see Array#select - def select + def select(&block) return results.enum_for(:select) unless block_given? # Sparkling magic! - results.select(&Proc.new) + results.select(&block) end # @return [Array] @@ -700,7 +700,7 @@ def first(limit = 1) # max_results is used to iterate through as many API requests as possible using # :skip and :limit paramter. # @!visibility private - def max_results(raw: false, on_batch: nil, discard_results: false) + def max_results(raw: false, on_batch: nil, discard_results: false, &block) compiled_query = compile batch_size = 1_000 results = [] @@ -725,7 +725,7 @@ def max_results(raw: false, on_batch: nil, discard_results: false) items = decode(items) unless raw # if a block is provided, we do not keep the results after processing. if block_given? - items.each(&Proc.new) + items.each(&block) else # concat results unless discard_results is true results += items unless discard_results @@ -796,15 +796,15 @@ def fetch!(compiled_query) # @yield a block to iterate for each object that matched the query. # @return [Array] if raw is set to true, a set of Parse JSON hashes. # @return [Array] if raw is set to false, a list of matching Parse::Object subclasses. - def results(raw: false) + def results(raw: false, &block) if @results.nil? if block_given? - max_results(raw: raw, &Proc.new) + max_results(raw: raw, &block) elsif @limit.is_a?(Numeric) response = fetch!(compile) return [] if response.error? items = raw ? response.results : decode(response.results) - return items.each(&Proc.new) if block_given? + return items.each(&block) if block_given? @results = items else @results = max_results(raw: raw) @@ -822,9 +822,9 @@ def results(raw: false) # @return [Array] if raw is set to true, a set of Parse JSON hashes. # @return [Array] if raw is set to false, a list of matching Parse::Object subclasses. # @see #results - def all(expressions = { limit: :max }) + def all(expressions = { limit: :max }, &block) conditions(expressions) - return results(&Proc.new) if block_given? + return results(&block) if block_given? results end diff --git a/lib/parse/webhooks.rb b/lib/parse/webhooks.rb index 8bb2a4d..23724ee 100644 --- a/lib/parse/webhooks.rb +++ b/lib/parse/webhooks.rb @@ -125,13 +125,12 @@ def routes # name to register with Parse server. # @yield the block that will handle of the webhook trigger or function. # @return (see routes) - def route(type, className, block = nil) + def route(type, className, &block) type = type.to_s.underscore.to_sym #support camelcase if type != :function && className.respond_to?(:parse_class) className = className.parse_class end className = className.to_s - block = Proc.new if block_given? if routes[type].nil? || block.respond_to?(:call) == false raise ArgumentError, "Invalid Webhook registration trigger #{type} #{className}" end