Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Ruby 2.7/ 3.0 #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/parse/api/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/parse/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/parse/client/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -125,15 +125,15 @@ def error?
# @param segment [Integer] the number of requests to send in each batch. Default 50.
# @return [Array<Parse::Response>] 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|
client.batch_request(BatchOperation.new(slice))
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

Expand Down
4 changes: 2 additions & 2 deletions lib/parse/client/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 10 additions & 10 deletions lib/parse/model/associations/collection_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/parse/model/associations/has_many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/parse/model/associations/relation_collection_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/parse/model/classes/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/parse/model/classes/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions lib/parse/model/core/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -35,15 +35,15 @@ 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?
raise ArgumentError, "Parse model with class name #{self.table} is not registered."
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
Expand Down
2 changes: 1 addition & 1 deletion lib/parse/model/core/fetching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/parse/model/core/querying.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ def each(constraints = {}, &block)
# by the server.
# @return [Array<Parse::Object>] 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

Expand Down
32 changes: 16 additions & 16 deletions lib/parse/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -654,33 +654,33 @@ 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

# @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]
Expand All @@ -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 = []
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -796,15 +796,15 @@ def fetch!(compiled_query)
# @yield a block to iterate for each object that matched the query.
# @return [Array<Hash>] if raw is set to true, a set of Parse JSON hashes.
# @return [Array<Parse::Object>] 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)
Expand All @@ -822,9 +822,9 @@ def results(raw: false)
# @return [Array<Hash>] if raw is set to true, a set of Parse JSON hashes.
# @return [Array<Parse::Object>] 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

Expand Down
2 changes: 1 addition & 1 deletion lib/parse/stack/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions lib/parse/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down