From 1b8bcdade1cd82450c14c76586a4ff7da55396a5 Mon Sep 17 00:00:00 2001 From: Anthony Persaud Date: Mon, 11 Jan 2021 12:05:57 -0800 Subject: [PATCH 01/15] Updated dependencies --- Gemfile.lock | 108 ++++++++++++++++++++++++++------------------------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 456ba65..6d2a957 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,77 +14,81 @@ PATH GEM remote: https://rubygems.org/ specs: - actionpack (6.0.3.2) - actionview (= 6.0.3.2) - activesupport (= 6.0.3.2) - rack (~> 2.0, >= 2.0.8) + actionpack (6.1.1) + actionview (= 6.1.1) + activesupport (= 6.1.1) + rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actionview (6.0.3.2) - activesupport (= 6.0.3.2) + actionview (6.1.1) + activesupport (= 6.1.1) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - active_model_serializers (0.10.10) - actionpack (>= 4.1, < 6.1) - activemodel (>= 4.1, < 6.1) + active_model_serializers (0.10.12) + actionpack (>= 4.1, < 6.2) + activemodel (>= 4.1, < 6.2) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activemodel (6.0.3.2) - activesupport (= 6.0.3.2) - activesupport (6.0.3.2) + activemodel (6.1.1) + activesupport (= 6.1.1) + activesupport (6.1.1) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) ansi (1.5.0) ast (2.4.1) backport (1.1.2) - benchmark (0.1.0) - binding_of_caller (0.8.0) + benchmark (0.1.1) + binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) builder (3.2.4) byebug (11.1.3) case_transform (0.2) activesupport coderay (1.1.3) - concurrent-ruby (1.1.6) + concurrent-ruby (1.1.7) crass (1.0.6) daemons (1.3.1) - debug_inspector (0.0.3) + debug_inspector (1.0.0) dotenv (2.7.6) e2mmap (0.1.0) - erubi (1.9.0) + erubi (1.10.0) eventmachine (1.2.7) faraday (0.17.3) multipart-post (>= 1.2, < 3) faraday_middleware (0.14.0) faraday (>= 0.7.4, < 1.0) - i18n (1.8.5) + i18n (1.8.7) concurrent-ruby (~> 1.0) jaro_winkler (1.5.4) jsonapi-renderer (0.2.2) - loofah (2.6.0) + kramdown (2.3.0) + rexml + kramdown-parser-gfm (1.1.0) + kramdown (~> 2.0) + loofah (2.8.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) - maruku (0.7.3) method_source (0.9.2) - mini_portile2 (2.4.0) - minitest (5.14.1) + mini_portile2 (2.5.0) + minitest (5.14.3) minitest-reporters (1.4.2) ansi builder minitest (>= 5.0) ruby-progressbar - moneta (1.3.0) + moneta (1.4.1) multipart-post (2.1.1) - nokogiri (1.10.10) - mini_portile2 (~> 2.4.0) - parallel (1.19.2) - parser (2.7.1.4) + nokogiri (1.11.1) + mini_portile2 (~> 2.5.0) + racc (~> 1.4) + parallel (1.20.1) + parser (2.7.2.0) ast (~> 2.4.1) pry (0.12.2) coderay (~> 1.1.0) @@ -94,6 +98,7 @@ GEM pry-stack_explorer (0.4.9.3) binding_of_caller (>= 0.7) pry (>= 0.9.11) + racc (1.5.2) rack (2.2.3) rack-test (1.1.0) rack (>= 1.0, < 3) @@ -103,51 +108,50 @@ GEM rails-html-sanitizer (1.3.0) loofah (~> 2.3) rainbow (3.0.0) - rake (13.0.1) - redcarpet (3.5.0) - redis (4.2.1) - regexp_parser (1.7.1) + rake (13.0.3) + redcarpet (3.5.1) + redis (4.2.5) + regexp_parser (2.0.3) reverse_markdown (2.0.0) nokogiri rexml (3.2.4) - rubocop (0.88.0) + rubocop (1.7.0) parallel (~> 1.10) - parser (>= 2.7.1.1) + parser (>= 2.7.1.5) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.7) + regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 0.1.0, < 1.0) + rubocop-ast (>= 1.2.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (0.2.0) - parser (>= 2.7.0.1) - ruby-progressbar (1.10.1) - solargraph (0.39.12) + rubocop-ast (1.4.0) + parser (>= 2.7.1.5) + ruby-progressbar (1.11.0) + solargraph (0.40.1) backport (~> 1.1) benchmark bundler (>= 1.17.2) e2mmap jaro_winkler (~> 1.5) - maruku (~> 0.7, >= 0.7.3) - nokogiri (~> 1.9, >= 1.9.1) + kramdown (~> 2.3) + kramdown-parser-gfm (~> 1.1) parser (~> 2.3) reverse_markdown (>= 1.0.5, < 3) - rubocop (~> 0.52) + rubocop (>= 0.52) thor (~> 1.0) tilt (~> 2.0) yard (~> 0.9, >= 0.9.24) - thin (1.7.2) + thin (1.8.0) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) rack (>= 1, < 3) thor (1.0.1) - thread_safe (0.3.6) tilt (2.0.10) - tzinfo (1.2.7) - thread_safe (~> 0.1) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) unicode-display_width (1.7.0) - yard (0.9.25) - zeitwerk (2.4.0) + yard (0.9.26) + zeitwerk (2.4.2) PLATFORMS ruby From 0128aec31dc2fac1b2fd1b3704d638291c826bda Mon Sep 17 00:00:00 2001 From: Henry Spindell Date: Fri, 9 Apr 2021 10:44:16 -0700 Subject: [PATCH 02/15] 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 c6e8695..1caf5e8 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 From 4a0f9cfc0f8c3c8f8b4317cacbcc61947be624e3 Mon Sep 17 00:00:00 2001 From: Henry Spindell Date: Tue, 27 Apr 2021 21:14:04 -0700 Subject: [PATCH 03/15] Uses explicit hash argument conversion --- lib/parse/model/associations/has_many.rb | 2 +- lib/parse/query.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/query.rb b/lib/parse/query.rb index 1caf5e8..d074d46 100644 --- a/lib/parse/query.rb +++ b/lib/parse/query.rb @@ -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 7f6b132f5ac281a678fc6f742d43b0fa97fb4823 Mon Sep 17 00:00:00 2001 From: Henry Spindell Date: Wed, 12 May 2021 18:04:18 -0700 Subject: [PATCH 04/15] Updates version + dependencies --- Gemfile.lock | 74 +++++++++++++++++++------------------- lib/parse/stack/version.rb | 2 +- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6d2a957..34b88e7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - parse-stack (1.9.1) + parse-stack (1.9.2) active_model_serializers (>= 0.9, < 1) activemodel (>= 5, < 7) activesupport (>= 5, < 7) @@ -14,15 +14,15 @@ PATH GEM remote: https://rubygems.org/ specs: - actionpack (6.1.1) - actionview (= 6.1.1) - activesupport (= 6.1.1) + actionpack (6.1.3.2) + actionview (= 6.1.3.2) + activesupport (= 6.1.3.2) rack (~> 2.0, >= 2.0.9) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actionview (6.1.1) - activesupport (= 6.1.1) + actionview (6.1.3.2) + activesupport (= 6.1.3.2) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -32,16 +32,16 @@ GEM activemodel (>= 4.1, < 6.2) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activemodel (6.1.1) - activesupport (= 6.1.1) - activesupport (6.1.1) + activemodel (6.1.3.2) + activesupport (= 6.1.3.2) + activesupport (6.1.3.2) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) zeitwerk (~> 2.3) ansi (1.5.0) - ast (2.4.1) + ast (2.4.2) backport (1.1.2) benchmark (0.1.1) binding_of_caller (1.0.0) @@ -51,44 +51,42 @@ GEM case_transform (0.2) activesupport coderay (1.1.3) - concurrent-ruby (1.1.7) + concurrent-ruby (1.1.8) crass (1.0.6) - daemons (1.3.1) - debug_inspector (1.0.0) + daemons (1.4.0) + debug_inspector (1.1.0) dotenv (2.7.6) e2mmap (0.1.0) erubi (1.10.0) eventmachine (1.2.7) - faraday (0.17.3) + faraday (0.17.4) multipart-post (>= 1.2, < 3) faraday_middleware (0.14.0) faraday (>= 0.7.4, < 1.0) - i18n (1.8.7) + i18n (1.8.10) concurrent-ruby (~> 1.0) jaro_winkler (1.5.4) jsonapi-renderer (0.2.2) - kramdown (2.3.0) + kramdown (2.3.1) rexml kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) - loofah (2.8.0) + loofah (2.9.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) method_source (0.9.2) - mini_portile2 (2.5.0) - minitest (5.14.3) - minitest-reporters (1.4.2) + minitest (5.14.4) + minitest-reporters (1.4.3) ansi builder minitest (>= 5.0) ruby-progressbar - moneta (1.4.1) + moneta (1.4.2) multipart-post (2.1.1) - nokogiri (1.11.1) - mini_portile2 (~> 2.5.0) + nokogiri (1.11.3-x86_64-darwin) racc (~> 1.4) parallel (1.20.1) - parser (2.7.2.0) + parser (3.0.1.1) ast (~> 2.4.1) pry (0.12.2) coderay (~> 1.1.0) @@ -111,23 +109,23 @@ GEM rake (13.0.3) redcarpet (3.5.1) redis (4.2.5) - regexp_parser (2.0.3) + regexp_parser (2.1.1) reverse_markdown (2.0.0) nokogiri - rexml (3.2.4) - rubocop (1.7.0) + rexml (3.2.5) + rubocop (1.14.0) parallel (~> 1.10) - parser (>= 2.7.1.5) + parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 1.2.0, < 2.0) + rubocop-ast (>= 1.5.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (1.4.0) - parser (>= 2.7.1.5) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.5.0) + parser (>= 3.0.1.1) ruby-progressbar (1.11.0) - solargraph (0.40.1) + solargraph (0.40.4) backport (~> 1.1) benchmark bundler (>= 1.17.2) @@ -135,7 +133,7 @@ GEM jaro_winkler (~> 1.5) kramdown (~> 2.3) kramdown-parser-gfm (~> 1.1) - parser (~> 2.3) + parser (~> 3.0) reverse_markdown (>= 1.0.5, < 3) rubocop (>= 0.52) thor (~> 1.0) @@ -145,16 +143,16 @@ GEM daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) rack (>= 1, < 3) - thor (1.0.1) + thor (1.1.0) tilt (2.0.10) tzinfo (2.0.4) concurrent-ruby (~> 1.0) - unicode-display_width (1.7.0) + unicode-display_width (2.0.0) yard (0.9.26) zeitwerk (2.4.2) PLATFORMS - ruby + x86_64-darwin-20 DEPENDENCIES byebug @@ -173,4 +171,4 @@ DEPENDENCIES yard (>= 0.9.11) BUNDLED WITH - 2.1.4 + 2.2.17 diff --git a/lib/parse/stack/version.rb b/lib/parse/stack/version.rb index 9f9a41a..dad9b0f 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.9.2" end end From 72fb8efd2b823ca8db030757b4b8fe793f11506c Mon Sep 17 00:00:00 2001 From: Bruno Enten Date: Tue, 28 Dec 2021 17:40:59 +0200 Subject: [PATCH 05/15] Remove upper bound for dependencies versions --- parse-stack.gemspec | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/parse-stack.gemspec b/parse-stack.gemspec index bfdbd32..b0a825b 100644 --- a/parse-stack.gemspec +++ b/parse-stack.gemspec @@ -27,14 +27,14 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.required_ruby_version = ">= 2.5.0" - spec.add_runtime_dependency "activemodel", [">= 5", "< 7"] - spec.add_runtime_dependency "active_model_serializers", [">= 0.9", "< 1"] - spec.add_runtime_dependency "activesupport", [">= 5", "< 7"] - spec.add_runtime_dependency "parallel", [">= 1.6", "< 2"] - spec.add_runtime_dependency "faraday", "< 1" - spec.add_runtime_dependency "faraday_middleware", [">= 0.9", "< 2"] - spec.add_runtime_dependency "moneta", "< 2" - spec.add_runtime_dependency "rack", ">= 2.0.6", "< 3" + spec.add_runtime_dependency "activemodel", [">= 5"] + spec.add_runtime_dependency "active_model_serializers", [">= 0.9"] + spec.add_runtime_dependency "activesupport", [">= 5"] + spec.add_runtime_dependency "parallel", [">= 1.6"] + spec.add_runtime_dependency "faraday" + spec.add_runtime_dependency "faraday_middleware", [">= 0.9"] + spec.add_runtime_dependency "moneta", + spec.add_runtime_dependency "rack", ">= 2.0.6" # spec.post_install_message = < Date: Tue, 28 Dec 2021 17:42:18 +0200 Subject: [PATCH 06/15] Remove extra comma --- parse-stack.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parse-stack.gemspec b/parse-stack.gemspec index b0a825b..ccfb474 100644 --- a/parse-stack.gemspec +++ b/parse-stack.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "parallel", [">= 1.6"] spec.add_runtime_dependency "faraday" spec.add_runtime_dependency "faraday_middleware", [">= 0.9"] - spec.add_runtime_dependency "moneta", + spec.add_runtime_dependency "moneta" spec.add_runtime_dependency "rack", ">= 2.0.6" # spec.post_install_message = < Date: Tue, 28 Dec 2021 18:18:08 +0200 Subject: [PATCH 07/15] remove dependence on AMS --- lib/parse/client.rb | 2 +- lib/parse/client/body_builder.rb | 2 +- lib/parse/model/core/properties.rb | 4 ++-- lib/parse/model/date.rb | 2 +- lib/parse/model/model.rb | 2 +- lib/parse/model/object.rb | 2 +- lib/parse/model/pointer.rb | 2 +- lib/parse/model/push.rb | 2 +- lib/parse/query.rb | 2 +- lib/parse/webhooks.rb | 2 +- lib/parse/webhooks/payload.rb | 4 ++-- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/parse/client.rb b/lib/parse/client.rb index 4384dab..3ed5c86 100644 --- a/lib/parse/client.rb +++ b/lib/parse/client.rb @@ -2,7 +2,7 @@ require "faraday_middleware" require "active_support" require "moneta" -require "active_model_serializers" + require "active_support/inflector" require "active_support/core_ext/object" require "active_support/core_ext/string" diff --git a/lib/parse/client/body_builder.rb b/lib/parse/client/body_builder.rb index 94037b8..8ac0c92 100644 --- a/lib/parse/client/body_builder.rb +++ b/lib/parse/client/body_builder.rb @@ -7,7 +7,7 @@ require_relative "protocol" require "active_support" require "active_support/core_ext" -require "active_model_serializers" + module Parse diff --git a/lib/parse/model/core/properties.rb b/lib/parse/model/core/properties.rb index 109c37d..42eb49c 100644 --- a/lib/parse/model/core/properties.rb +++ b/lib/parse/model/core/properties.rb @@ -7,9 +7,9 @@ require "active_support/core_ext" require "active_support/core_ext/object" require "active_support/inflector" -require "active_model_serializers" + require "active_support/inflector" -require "active_model_serializers" + require "active_support/hash_with_indifferent_access" require "time" diff --git a/lib/parse/model/date.rb b/lib/parse/model/date.rb index 0193c4a..6a84c91 100644 --- a/lib/parse/model/date.rb +++ b/lib/parse/model/date.rb @@ -10,7 +10,7 @@ require "active_support/core_ext/date/calculations" require "active_support/core_ext/date_time/calculations" require "active_support/core_ext/time/calculations" -require "active_model_serializers" + require_relative "model" module Parse diff --git a/lib/parse/model/model.rb b/lib/parse/model/model.rb index 33f8ef3..bd79100 100644 --- a/lib/parse/model/model.rb +++ b/lib/parse/model/model.rb @@ -5,7 +5,7 @@ require "active_support" require "active_support/inflector" require "active_support/core_ext/object" -require "active_model_serializers" + require_relative "../client" module Parse diff --git a/lib/parse/model/object.rb b/lib/parse/model/object.rb index 79d249d..53ab5ad 100644 --- a/lib/parse/model/object.rb +++ b/lib/parse/model/object.rb @@ -7,7 +7,7 @@ require "active_support/core_ext" require "active_support/core_ext/object" require "active_support/core_ext/string" -require "active_model_serializers" + require "time" require "open-uri" diff --git a/lib/parse/model/pointer.rb b/lib/parse/model/pointer.rb index 967b2ea..431ed70 100644 --- a/lib/parse/model/pointer.rb +++ b/lib/parse/model/pointer.rb @@ -5,7 +5,7 @@ require "active_support" require "active_support/inflector" require "active_support/core_ext" -require "active_model_serializers" + require_relative "model" module Parse diff --git a/lib/parse/model/push.rb b/lib/parse/model/push.rb index 1520ab9..d1e831a 100644 --- a/lib/parse/model/push.rb +++ b/lib/parse/model/push.rb @@ -3,7 +3,7 @@ require_relative "../query.rb" require_relative "../client.rb" -require "active_model_serializers" + module Parse # This class represents the API to send push notification to devices that are diff --git a/lib/parse/query.rb b/lib/parse/query.rb index a27b4cc..3d21d0e 100644 --- a/lib/parse/query.rb +++ b/lib/parse/query.rb @@ -6,7 +6,7 @@ require_relative "query/constraints" require_relative "query/ordering" require "active_model" -require "active_model_serializers" + require "active_support" require "active_support/inflector" require "active_support/core_ext" diff --git a/lib/parse/webhooks.rb b/lib/parse/webhooks.rb index 23724ee..e122f85 100644 --- a/lib/parse/webhooks.rb +++ b/lib/parse/webhooks.rb @@ -6,7 +6,7 @@ require "active_support/inflector" require "active_support/core_ext/object" require "active_support/core_ext" -require "active_model_serializers" + require "rack" require_relative "client" require_relative "stack" diff --git a/lib/parse/webhooks/payload.rb b/lib/parse/webhooks/payload.rb index 25f17cc..a18d1f2 100644 --- a/lib/parse/webhooks/payload.rb +++ b/lib/parse/webhooks/payload.rb @@ -7,7 +7,7 @@ require "active_support/core_ext/object" require "active_support/core_ext/string" require "active_support/core_ext" -require "active_model_serializers" + module Parse class Webhooks @@ -125,7 +125,7 @@ def parse_class def parse_id return nil unless @object.present? @object[Parse::Model::OBJECT_ID] || @object[:objectId] - end; + end; alias_method :objectId, :parse_id # true if this is a webhook trigger request. From 2d5d0a75686eac183f8fc6263a5c6b24e33819ce Mon Sep 17 00:00:00 2001 From: Bruno Enten Date: Mon, 28 Mar 2022 17:57:46 +0200 Subject: [PATCH 08/15] ignore leading underscore --- lib/parse/model/core/builder.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/parse/model/core/builder.rb b/lib/parse/model/core/builder.rb index e95147c..8c72b8c 100644 --- a/lib/parse/model/core/builder.rb +++ b/lib/parse/model/core/builder.rb @@ -43,6 +43,10 @@ def self.build!(schema) raise ArgumentError, "No valid className provided for schema hash" end + # Remove leading underscore, as ruby constants have to start with an uppercase letter + + className = className[1..] if className[0] == '_' + begin klass = Parse::Model.find_class className klass = ::Object.const_get(className.to_parse_class) if klass.nil? From b475475bdd938b3fcd1d6b866b3d890479780bd4 Mon Sep 17 00:00:00 2001 From: Bruno Enten Date: Wed, 30 Mar 2022 15:49:28 +0200 Subject: [PATCH 09/15] ruby 3.0 compatibility --- lib/parse/webhooks.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/parse/webhooks.rb b/lib/parse/webhooks.rb index e122f85..d4d261c 100644 --- a/lib/parse/webhooks.rb +++ b/lib/parse/webhooks.rb @@ -53,18 +53,18 @@ def self.webhook_function(functionName, block = nil) # @yield the body of the function to be evaluated in the scope of a {Parse::Webhooks::Payload} instance. # @param block [Symbol] the name of the method to call, if no block is passed. # @return (see Parse::Webhooks.route) - def self.webhook(type, block = nil) + def self.webhook(type, function=nil, &block) if type == :function - unless block.is_a?(String) || block.is_a?(Symbol) - raise ArgumentError, "Invalid Cloud Code function name: #{block}" + unless function.is_a?(String) || function.is_a?(Symbol) + raise ArgumentError, "Invalid Cloud Code function name: #{function}" end - Parse::Webhooks.route(:function, block, &Proc.new) + Parse::Webhooks.route(:function, function, block) # then block must be a symbol or a string else - if block_given? - Parse::Webhooks.route(type, self, &Proc.new) - else + if block Parse::Webhooks.route(type, self, block) + else + Parse::Webhooks.route(type, self, function) end end #if block @@ -125,7 +125,7 @@ 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) + 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 From 7a76ffde92fedde2d48a400460bda6f8f4c6e62d Mon Sep 17 00:00:00 2001 From: Bruno Enten Date: Thu, 31 Mar 2022 15:02:01 +0200 Subject: [PATCH 10/15] fix block param --- lib/parse/webhooks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/parse/webhooks.rb b/lib/parse/webhooks.rb index d4d261c..a14e942 100644 --- a/lib/parse/webhooks.rb +++ b/lib/parse/webhooks.rb @@ -125,7 +125,7 @@ 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) + 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 From 4cd635612c2152f7e3d2956b92dd66dfbc4b51c8 Mon Sep 17 00:00:00 2001 From: Bruno Enten Date: Thu, 31 Mar 2022 15:29:58 +0200 Subject: [PATCH 11/15] more ruby 3 compatibility --- lib/parse/stack/tasks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/parse/stack/tasks.rb b/lib/parse/stack/tasks.rb index e3473aa..5bc1142 100644 --- a/lib/parse/stack/tasks.rb +++ b/lib/parse/stack/tasks.rb @@ -117,7 +117,7 @@ def install_tasks task :triggers => :verify_env do endpoint = ENV["HOOKS_URL"] - Parse::Webhooks.register_triggers!(endpoint, { include_wildcard: true }) do |trigger, name| + Parse::Webhooks.register_triggers!(endpoint, include_wildcard: true) do |trigger, name| puts "[+] #{trigger.to_s.ljust(12, " ")} - #{name}" end end From 302900ed817b6bff0b7c3d99c727050ee0be930c Mon Sep 17 00:00:00 2001 From: Bruno Enten Date: Fri, 15 Jul 2022 13:03:16 +0300 Subject: [PATCH 12/15] faraday 2 compatibility --- Gemfile.lock | 17 +++++++++-------- lib/parse/client.rb | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 6bd582b..981540d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,14 +2,14 @@ PATH remote: . specs: parse-stack (1.10.0) - active_model_serializers (>= 0.9, < 1) - activemodel (>= 5, < 7) - activesupport (>= 5, < 7) - faraday (< 1) - faraday_middleware (>= 0.9, < 2) - moneta (< 2) - parallel (>= 1.6, < 2) - rack (>= 2.0.6, < 3) + active_model_serializers (>= 0.9) + activemodel (>= 5) + activesupport (>= 5) + faraday + faraday_middleware (>= 0.9) + moneta + parallel (>= 1.6) + rack (>= 2.0.6) GEM remote: https://rubygems.org/ @@ -155,6 +155,7 @@ GEM PLATFORMS x86_64-darwin-20 + x86_64-linux DEPENDENCIES byebug diff --git a/lib/parse/client.rb b/lib/parse/client.rb index 3ed5c86..85065e0 100644 --- a/lib/parse/client.rb +++ b/lib/parse/client.rb @@ -481,7 +481,7 @@ def request(method, uri = nil, body: nil, query: nil, headers: nil, opts: {}) retry end raise - rescue Faraday::Error::ClientError, Net::OpenTimeout => e + rescue Faraday::ClientError, Net::OpenTimeout => e if _retry_count > 0 warn "[Parse:Retry] Retries remaining #{_retry_count} : #{_request}" _retry_count -= 1 From 51fd8971eccfe3526abd1191d12110a5a2d29ff9 Mon Sep 17 00:00:00 2001 From: Bruno Enten Date: Sat, 16 Jul 2022 12:13:58 +0300 Subject: [PATCH 13/15] Remove models overrides templates Can't have two autoloaded files defining the same class. It results in inconsistent behavior. Built-in parse classes have to be properly reopened with class_eval. --- lib/parse/stack/generators/rails.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/parse/stack/generators/rails.rb b/lib/parse/stack/generators/rails.rb index 858bcc2..b435402 100644 --- a/lib/parse/stack/generators/rails.rb +++ b/lib/parse/stack/generators/rails.rb @@ -16,11 +16,11 @@ class InstallGenerator < Rails::Generators::Base # @!visibility private def generate_initializer copy_file "parse.rb", "config/initializers/parse.rb" - copy_file "model_user.rb", File.join("app/models", "user.rb") - copy_file "model_role.rb", File.join("app/models", "role.rb") - copy_file "model_session.rb", File.join("app/models", "session.rb") - copy_file "model_installation.rb", File.join("app/models", "installation.rb") - copy_file "webhooks.rb", File.join("app/models", "webhooks.rb") + #copy_file "model_user.rb", File.join("app/models", "user.rb") + #copy_file "model_role.rb", File.join("app/models", "role.rb") + #copy_file "model_session.rb", File.join("app/models", "session.rb") + #copy_file "model_installation.rb", File.join("app/models", "installation.rb") + #copy_file "webhooks.rb", File.join("app/models", "webhooks.rb") end end From 0e601845545a83654fd1d373c63ab95ffa067ffa Mon Sep 17 00:00:00 2001 From: Bruno Enten Date: Sat, 17 Sep 2022 11:43:36 +0300 Subject: [PATCH 14/15] compatibility with Rails strong parameters --- lib/parse/model/object.rb | 7 ++--- test/lib/parse/models/attributes_test.rb | 34 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 test/lib/parse/models/attributes_test.rb diff --git a/lib/parse/model/object.rb b/lib/parse/model/object.rb index 53ab5ad..3cb0e4b 100644 --- a/lib/parse/model/object.rb +++ b/lib/parse/model/object.rb @@ -298,11 +298,12 @@ def as_json(opts = nil) def initialize(opts = {}) if opts.is_a?(String) #then it's the objectId @id = opts.to_s - elsif opts.is_a?(Hash) + elsif opts.respond_to?(:to_h) #if the objectId is provided we will consider the object pristine #and not track dirty items - dirty_track = opts[Parse::Model::OBJECT_ID] || opts[:objectId] || opts[:id] - apply_attributes!(opts, dirty_track: !dirty_track) + _attributes = opts.to_h + dirty_track = _attributes[Parse::Model::OBJECT_ID] || _attributes[:objectId] || _attributes[:id] + apply_attributes!(_attributes, dirty_track: !dirty_track) end # if no ACLs, then apply the class default acls diff --git a/test/lib/parse/models/attributes_test.rb b/test/lib/parse/models/attributes_test.rb new file mode 100644 index 0000000..9344e05 --- /dev/null +++ b/test/lib/parse/models/attributes_test.rb @@ -0,0 +1,34 @@ +require_relative "../../../test_helper" + +class TestAttributesClass < Parse::Object + property :main_name +end + +# Mock Rails Action Controller Parameters +class ActionControllerParametersMock + def initialize(_attributes) + @attributes = _attributes + end + + def to_h + @attributes + end +end + +class TestAttributesModule < Minitest::Test + def setup + end + + def test_attribution_from_hash + test_object = TestAttributesClass.new({main_name: 'test_name'}) + assert_equal test_object.main_name, 'test_name' + assert_equal test_object.mainName, 'test_name' + end + + def test_attribution_from_params + params = ActionControllerParametersMock.new({main_name: 'test_name'}) + test_object = TestAttributesClass.new(params) + assert_equal test_object.main_name, 'test_name' + assert_equal test_object.mainName, 'test_name' + end +end From f40e6cdc5d02ac048b15e3f0a002b869980474e7 Mon Sep 17 00:00:00 2001 From: Bruno Enten Date: Mon, 19 Sep 2022 10:58:34 +0300 Subject: [PATCH 15/15] update doc with reopening builtin classes --- README.md | 33 +++++++++++++++++++++++++++++++++ lib/parse/model/classes/user.rb | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e84633..b11ff20 100644 --- a/README.md +++ b/README.md @@ -647,6 +647,39 @@ data.acl # => ACL({"role:Admin"=>{"read"=>true, "write"=>true}}) For more information about Parse record ACLs, see the documentation at [Security](http://docs.parseplatform.org/rest/guide/#security) +## Builtin parse collections + +These classes match parse builtin collections. Do not redeclare them as rails autoloader don't support multiple class declarations. To add properties and methods to these classes, properly reopen them with overrides, using this class_eval method. + +First, append this to config/application.rb + +```ruby +## +# Don't autoload overrides but preload them instead + overrides = "#{Rails.root}/app/overrides" + Rails.autoloaders.main.ignore(overrides) + + config.to_prepare do + Dir.glob("#{overrides}/**/*_override.rb").each do |override| + load override + end + end +``` + +Then, create the folder app/overrides/models. Create a file named [collection]_override.rb in this folder to reopen one of these classes. Example with the _User collection: + +```ruby +# app/overrides/models/user_override.rb +Parse::User.class_eval do + has_many :created_articles, as: :articles, field: :creator + + property :first_name + property :last_name + property :picture +end +``` + + ### [Parse::Session](https://www.modernistik.com/gems/parse-stack/Parse/Session.html) This class represents the data and columns contained in the standard Parse `_Session` collection. You may add additional properties and methods to this class. See [Session API Reference](https://www.modernistik.com/gems/parse-stack/Parse/Session.html). You may call `Parse.use_shortnames!` to use `Session` in addition to `Parse::Session`. diff --git a/lib/parse/model/classes/user.rb b/lib/parse/model/classes/user.rb index a15c437..c3f90c8 100644 --- a/lib/parse/model/classes/user.rb +++ b/lib/parse/model/classes/user.rb @@ -29,7 +29,7 @@ class InvalidEmailAddress < Error; end # The main class representing the _User table in Parse. A user can either be signed up or anonymous. # All users need to have a username and a password, with email being optional but globally unique if set. - # You may add additional properties by redeclaring the class to match your specific schema. + # You may add additional properties by reopening the class to match your specific schema. # # The default schema for the {User} class is as follows: #