parse-stack 1.8.0 → 1.8.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 +4 -4
- data/.solargraph.yml +23 -0
- data/.travis.yml +0 -1
- data/Gemfile +13 -12
- data/Gemfile.lock +88 -51
- data/README.md +2 -4
- data/Rakefile +14 -14
- data/lib/parse/api/aggregate.rb +4 -7
- data/lib/parse/api/all.rb +1 -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 +7 -12
- 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 +54 -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 +14 -21
- data/lib/parse/model/associations/collection_proxy.rb +328 -329
- data/lib/parse/model/associations/has_many.rb +18 -25
- data/lib/parse/model/associations/has_one.rb +6 -11
- data/lib/parse/model/associations/pointer_collection_proxy.rb +5 -8
- 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 +20 -16
- 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 +51 -66
- data/lib/parse/model/core/querying.rb +291 -294
- data/lib/parse/model/core/schema.rb +89 -92
- data/lib/parse/model/date.rb +16 -17
- 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 +47 -53
- 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 +34 -35
- data/lib/parse/query/constraint.rb +4 -6
- data/lib/parse/query/constraints.rb +21 -29
- data/lib/parse/query/operation.rb +8 -11
- data/lib/parse/query/ordering.rb +45 -49
- data/lib/parse/stack.rb +11 -12
- 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 +25 -25
- data/parse-stack.png +0 -0
- metadata +13 -7
- data/.github/parse-ruby-sdk.png +0 -0
data/lib/parse/model/push.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require
|
4
|
+
require_relative "../query.rb"
|
5
|
+
require_relative "../client.rb"
|
6
|
+
require "active_model_serializers"
|
7
|
+
|
7
8
|
module Parse
|
8
9
|
# This class represents the API to send push notification to devices that are
|
9
10
|
# available in the Installation table. Push notifications are implemented
|
@@ -68,7 +69,7 @@ module Parse
|
|
68
69
|
# @!attribute [rw] channels
|
69
70
|
# @return [Array] an array of strings for subscribed channels.
|
70
71
|
attr_accessor :query, :alert, :badge, :sound, :title, :data,
|
71
|
-
|
72
|
+
:expiration_time, :expiration_interval, :push_time, :channels
|
72
73
|
|
73
74
|
alias_method :message, :alert
|
74
75
|
alias_method :message=, :alert=
|
@@ -134,14 +135,13 @@ module Parse
|
|
134
135
|
msg = {
|
135
136
|
data: {
|
136
137
|
alert: alert,
|
137
|
-
badge: badge || "Increment"
|
138
|
-
}
|
138
|
+
badge: badge || "Increment",
|
139
|
+
},
|
139
140
|
}
|
140
141
|
msg[:data][:sound] = sound if sound.present?
|
141
142
|
msg[:data][:title] = title if title.present?
|
142
143
|
msg[:data].merge! @data if @data.is_a?(Hash)
|
143
144
|
|
144
|
-
|
145
145
|
if @expiration_time.present?
|
146
146
|
msg[:expiration_time] = @expiration_time.respond_to?(:iso8601) ? @expiration_time.iso8601(3) : @expiration_time
|
147
147
|
end
|
@@ -170,9 +170,7 @@ module Parse
|
|
170
170
|
def send(message = nil)
|
171
171
|
@alert = message if message.is_a?(String)
|
172
172
|
@data = message if message.is_a?(Hash)
|
173
|
-
client.push(
|
173
|
+
client.push(payload.as_json)
|
174
174
|
end
|
175
|
-
|
176
175
|
end
|
177
|
-
|
178
176
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
4
|
+
require "active_support"
|
5
|
+
require "active_support/values/time_zone"
|
6
6
|
require_relative "model"
|
7
7
|
|
8
8
|
module Parse
|
@@ -118,7 +118,7 @@ module Parse
|
|
118
118
|
@name = timezone
|
119
119
|
@zone = nil
|
120
120
|
else
|
121
|
-
raise ArgumentError,
|
121
|
+
raise ArgumentError, "Invalid value passed to Parse::TimeZone#zone."
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -137,7 +137,5 @@ module Parse
|
|
137
137
|
def valid?
|
138
138
|
ActiveSupport::TimeZone[to_s].present?
|
139
139
|
end
|
140
|
-
|
141
140
|
end
|
142
|
-
|
143
141
|
end
|
data/lib/parse/query.rb
CHANGED
@@ -5,11 +5,11 @@ require_relative "client"
|
|
5
5
|
require_relative "query/operation"
|
6
6
|
require_relative "query/constraints"
|
7
7
|
require_relative "query/ordering"
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
8
|
+
require "active_model"
|
9
|
+
require "active_model_serializers"
|
10
|
+
require "active_support"
|
11
|
+
require "active_support/inflector"
|
12
|
+
require "active_support/core_ext"
|
13
13
|
|
14
14
|
module Parse
|
15
15
|
# The {Parse::Query} class provides the lower-level querying interface for
|
@@ -62,7 +62,7 @@ module Parse
|
|
62
62
|
# You can build your own custom query constraints by creating a `Parse::Constraint`
|
63
63
|
# subclass. For all these `where` clauses assume `q` is a `Parse::Query` object.
|
64
64
|
class Query
|
65
|
-
extend
|
65
|
+
extend ::ActiveModel::Callbacks
|
66
66
|
include Parse::Client::Connectable
|
67
67
|
include Enumerable
|
68
68
|
# @!group Callbacks
|
@@ -196,8 +196,8 @@ module Parse
|
|
196
196
|
# @param table [String] the name of the Parse collection to query. (ex. "_User")
|
197
197
|
# @param constraints [Hash] a set of query constraints.
|
198
198
|
# @return [Query] a new query for the Parse collection with the passed in constraints.
|
199
|
-
def all(table, constraints = {limit: :max})
|
200
|
-
self.new(table, constraints.reverse_merge({limit: :max}))
|
199
|
+
def all(table, constraints = { limit: :max })
|
200
|
+
self.new(table, constraints.reverse_merge({ limit: :max }))
|
201
201
|
end
|
202
202
|
|
203
203
|
# This methods takes a set of constraints and merges them to build a final
|
@@ -205,7 +205,7 @@ module Parse
|
|
205
205
|
# @param where [Array] an array of {Parse::Constraint} objects.
|
206
206
|
# @return [Hash] a hash representing the compiled query
|
207
207
|
def compile_where(where)
|
208
|
-
constraint_reduce(
|
208
|
+
constraint_reduce(where)
|
209
209
|
end
|
210
210
|
|
211
211
|
# @!visibility private
|
@@ -214,7 +214,7 @@ module Parse
|
|
214
214
|
clauses.reduce({}) do |clause, subclause|
|
215
215
|
#puts "Merging Subclause: #{subclause.as_json}"
|
216
216
|
|
217
|
-
clause.deep_merge!(
|
217
|
+
clause.deep_merge!(subclause.as_json || {})
|
218
218
|
clause
|
219
219
|
end
|
220
220
|
end
|
@@ -228,7 +228,6 @@ module Parse
|
|
228
228
|
query.define_singleton_method(:inspect) { self.results.to_a.inspect }
|
229
229
|
end
|
230
230
|
end
|
231
|
-
|
232
231
|
end
|
233
232
|
|
234
233
|
# @!attribute [r] client
|
@@ -334,6 +333,7 @@ module Parse
|
|
334
333
|
end # each
|
335
334
|
self #chaining
|
336
335
|
end
|
336
|
+
|
337
337
|
alias_method :query, :conditions
|
338
338
|
alias_method :append, :conditions
|
339
339
|
|
@@ -418,7 +418,7 @@ module Parse
|
|
418
418
|
# @param amount [Integer] The number of records to skip.
|
419
419
|
# @return [self]
|
420
420
|
def skip(amount)
|
421
|
-
@skip = [0,amount.to_i].max
|
421
|
+
@skip = [0, amount.to_i].max
|
422
422
|
@results = nil
|
423
423
|
self #chaining
|
424
424
|
end
|
@@ -438,7 +438,7 @@ module Parse
|
|
438
438
|
# @return [self]
|
439
439
|
def limit(count)
|
440
440
|
if count.is_a?(Numeric)
|
441
|
-
@limit = [
|
441
|
+
@limit = [0, count.to_i].max
|
442
442
|
elsif count == :max
|
443
443
|
@limit = :max
|
444
444
|
else
|
@@ -584,7 +584,7 @@ module Parse
|
|
584
584
|
# @return [Query] the combined query with an OR clause.
|
585
585
|
def or_where(where_clauses = [])
|
586
586
|
where_clauses = where_clauses.where if where_clauses.is_a?(Parse::Query)
|
587
|
-
where_clauses = Parse::Query.new(@table, where_clauses
|
587
|
+
where_clauses = Parse::Query.new(@table, where_clauses).where if where_clauses.is_a?(Hash)
|
588
588
|
return self if where_clauses.blank?
|
589
589
|
# we can only have one compound query constraint. If we need to add another OR clause
|
590
590
|
# let's find the one we have (if any)
|
@@ -594,7 +594,7 @@ module Parse
|
|
594
594
|
# if we don't have a OR clause to reuse, then create a new one with then
|
595
595
|
# current set of constraints
|
596
596
|
if compound.blank?
|
597
|
-
compound = Parse::Constraint::CompoundQueryConstraint.new :or, [
|
597
|
+
compound = Parse::Constraint::CompoundQueryConstraint.new :or, [Parse::Query.compile_where(remaining_clauses)]
|
598
598
|
end
|
599
599
|
# then take the where clauses from the second query and append them.
|
600
600
|
compound.value.push Parse::Query.compile_where(where_clauses)
|
@@ -606,10 +606,10 @@ module Parse
|
|
606
606
|
# @see #or_where
|
607
607
|
# @return [Query] the combined query with an OR clause.
|
608
608
|
def |(other_query)
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
609
|
+
raise ArgumentError, "Parse queries must be of the same class #{@table}." unless @table == other_query.table
|
610
|
+
copy_query = self.clone
|
611
|
+
copy_query.or_where other_query.where
|
612
|
+
copy_query
|
613
613
|
end
|
614
614
|
|
615
615
|
# Queries can be made using distinct, allowing you find unique values for a specified field.
|
@@ -635,7 +635,7 @@ module Parse
|
|
635
635
|
compile_query[:distinct] = Query.format_field(field).to_sym
|
636
636
|
@count = old_count_value
|
637
637
|
# perform aggregation
|
638
|
-
return client.aggregate_objects(@table, compile_query.as_json, _opts
|
638
|
+
return client.aggregate_objects(@table, compile_query.as_json, _opts).result
|
639
639
|
else
|
640
640
|
raise ArgumentError, "Invalid field name passed to `distinct`."
|
641
641
|
end
|
@@ -654,7 +654,7 @@ module Parse
|
|
654
654
|
def count
|
655
655
|
old_value = @count
|
656
656
|
@count = 1
|
657
|
-
res = client.find_objects(@table, compile.as_json, _opts
|
657
|
+
res = client.find_objects(@table, compile.as_json, _opts).count
|
658
658
|
@count = old_value
|
659
659
|
res
|
660
660
|
end
|
@@ -663,8 +663,8 @@ module Parse
|
|
663
663
|
# @return [Array]
|
664
664
|
# @see Array#each
|
665
665
|
def each
|
666
|
-
|
667
|
-
|
666
|
+
return results.enum_for(:each) unless block_given? # Sparkling magic!
|
667
|
+
results.each(&Proc.new)
|
668
668
|
end
|
669
669
|
|
670
670
|
# @yield a block yield for each object in the result
|
@@ -718,7 +718,7 @@ module Parse
|
|
718
718
|
compiled_query[:limit] = _limit if _limit < batch_size
|
719
719
|
end
|
720
720
|
|
721
|
-
response = fetch!(
|
721
|
+
response = fetch!(compiled_query)
|
722
722
|
break if response.error? || response.results.empty?
|
723
723
|
|
724
724
|
items = response.results
|
@@ -766,13 +766,13 @@ module Parse
|
|
766
766
|
# @param compiled_query [Hash] the compiled query
|
767
767
|
# @return [Parse::Response] a response for a query request.
|
768
768
|
def fetch!(compiled_query)
|
769
|
-
|
770
|
-
response = client.find_objects(@table, compiled_query.as_json, _opts )
|
769
|
+
response = client.find_objects(@table, compiled_query.as_json, _opts)
|
771
770
|
if response.error?
|
772
771
|
puts "[ParseQuery] #{response.error}"
|
773
772
|
end
|
774
773
|
response
|
775
774
|
end
|
775
|
+
|
776
776
|
alias_method :execute!, :fetch!
|
777
777
|
|
778
778
|
# Executes the query and builds the result set of Parse::Objects that matched.
|
@@ -801,7 +801,7 @@ module Parse
|
|
801
801
|
if block_given?
|
802
802
|
max_results(raw: raw, &Proc.new)
|
803
803
|
elsif @limit.is_a?(Numeric)
|
804
|
-
response = fetch!(
|
804
|
+
response = fetch!(compile)
|
805
805
|
return [] if response.error?
|
806
806
|
items = raw ? response.results : decode(response.results)
|
807
807
|
return items.each(&Proc.new) if block_given?
|
@@ -812,6 +812,7 @@ module Parse
|
|
812
812
|
end
|
813
813
|
@results
|
814
814
|
end
|
815
|
+
|
815
816
|
alias_method :result, :results
|
816
817
|
|
817
818
|
# Similar to {#results} but takes an additional set of conditions to apply. This
|
@@ -821,7 +822,7 @@ module Parse
|
|
821
822
|
# @return [Array<Hash>] if raw is set to true, a set of Parse JSON hashes.
|
822
823
|
# @return [Array<Parse::Object>] if raw is set to false, a list of matching Parse::Object subclasses.
|
823
824
|
# @see #results
|
824
|
-
def all(expressions = {limit: :max})
|
825
|
+
def all(expressions = { limit: :max })
|
825
826
|
conditions(expressions)
|
826
827
|
return results(&Proc.new) if block_given?
|
827
828
|
results
|
@@ -859,9 +860,9 @@ module Parse
|
|
859
860
|
q[:limit] = @limit if @limit.is_a?(Numeric) && @limit > 0
|
860
861
|
q[:skip] = @skip if @skip > 0
|
861
862
|
|
862
|
-
q[:include] = @includes.join(
|
863
|
-
q[:keys] = @keys.join(
|
864
|
-
q[:order] = @order.join(
|
863
|
+
q[:include] = @includes.join(",") unless @includes.empty?
|
864
|
+
q[:keys] = @keys.join(",") unless @keys.empty?
|
865
|
+
q[:order] = @order.join(",") unless @order.empty?
|
865
866
|
unless @where.empty?
|
866
867
|
q[:where] = Parse::Query.compile_where(@where)
|
867
868
|
q[:where] = q[:where].to_json if encode
|
@@ -881,15 +882,13 @@ module Parse
|
|
881
882
|
|
882
883
|
# @return [Hash] a hash representing just the `where` clause of this query.
|
883
884
|
def compile_where
|
884
|
-
self.class.compile_where(
|
885
|
+
self.class.compile_where(@where || [])
|
885
886
|
end
|
886
887
|
|
887
888
|
# Retruns a formatted JSON string representing the query, useful for debugging.
|
888
889
|
# @return [String]
|
889
890
|
def pretty
|
890
|
-
JSON.pretty_generate(
|
891
|
+
JSON.pretty_generate(as_json)
|
891
892
|
end
|
892
|
-
|
893
893
|
end # Query
|
894
|
-
|
895
894
|
end # Parse
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require_relative
|
5
|
-
require
|
6
|
-
require
|
4
|
+
require_relative "operation"
|
5
|
+
require "time"
|
6
|
+
require "date"
|
7
7
|
|
8
8
|
module Parse
|
9
9
|
# Constraints are the heart of the Parse::Query system.
|
@@ -39,12 +39,11 @@ module Parse
|
|
39
39
|
# it most likely is just the field name, so let's assume they want
|
40
40
|
# the default equality operation.
|
41
41
|
if operation.is_a?(Operation) == false && operation.respond_to?(:to_sym)
|
42
|
-
|
42
|
+
operation = Operation.new(operation.to_sym, self.class.operand)
|
43
43
|
end
|
44
44
|
@operation = operation
|
45
45
|
@value = value
|
46
46
|
yield(self) if block_given?
|
47
|
-
|
48
47
|
end
|
49
48
|
|
50
49
|
class << self
|
@@ -122,7 +121,6 @@ module Parse
|
|
122
121
|
end
|
123
122
|
d
|
124
123
|
end
|
125
|
-
|
126
124
|
end
|
127
125
|
|
128
126
|
# @return [Integer] the precedence of this constraint
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require_relative
|
4
|
+
require_relative "constraint"
|
5
5
|
|
6
6
|
# Each constraint type is a subclass of Parse::Constraint
|
7
7
|
# We register each keyword (which is the Parse query operator)
|
@@ -60,7 +60,7 @@ module Parse
|
|
60
60
|
value = formatted_value
|
61
61
|
# if it is already a pointer value, just return the constraint. Allows for
|
62
62
|
# supporting strings, symbols and pointers.
|
63
|
-
return { @operation.operand
|
63
|
+
return { @operation.operand => value } if value.is_a?(Parse::Pointer)
|
64
64
|
|
65
65
|
begin
|
66
66
|
klass = className.constantize
|
@@ -79,9 +79,8 @@ module Parse
|
|
79
79
|
raise ArgumentError, "#{self.class}: value must be of string type representing a Parse object id."
|
80
80
|
end
|
81
81
|
value.strip!
|
82
|
-
return { @operation.operand
|
82
|
+
return { @operation.operand => klass.pointer(value) }
|
83
83
|
end
|
84
|
-
|
85
84
|
end
|
86
85
|
|
87
86
|
# Equivalent to the `$or` Parse query operation. This is useful if you want to
|
@@ -101,7 +100,6 @@ module Parse
|
|
101
100
|
or_clauses = formatted_value
|
102
101
|
return { :$or => Array.wrap(or_clauses) }
|
103
102
|
end
|
104
|
-
|
105
103
|
end
|
106
104
|
|
107
105
|
# Equivalent to the `$lte` Parse query operation. The alias `on_or_before` is provided for readability.
|
@@ -154,6 +152,7 @@ module Parse
|
|
154
152
|
register :less_than
|
155
153
|
register :before
|
156
154
|
end
|
155
|
+
|
157
156
|
# Equivalent to the `$gt` Parse query operation. The alias `after` is provided for readability.
|
158
157
|
# q.where :field.gt => value
|
159
158
|
# q.where :field.after => date
|
@@ -252,13 +251,12 @@ module Parse
|
|
252
251
|
end
|
253
252
|
|
254
253
|
if value == true
|
255
|
-
return { @operation.operand => { key => false} }
|
254
|
+
return { @operation.operand => { key => false } }
|
256
255
|
else
|
257
256
|
#current bug in parse where if you want exists => true with geo queries
|
258
257
|
# we should map it to a "not equal to null" constraint
|
259
258
|
return { @operation.operand => { Parse::Constraint::NotEqualConstraint.key => nil } }
|
260
259
|
end
|
261
|
-
|
262
260
|
end
|
263
261
|
end
|
264
262
|
|
@@ -319,7 +317,6 @@ module Parse
|
|
319
317
|
val = [val].compact unless val.is_a?(Array)
|
320
318
|
{ @operation.operand => { key => val } }
|
321
319
|
end
|
322
|
-
|
323
320
|
end
|
324
321
|
|
325
322
|
# Equivalent to the `$nin` Parse query operation. Checks whether the value in
|
@@ -357,7 +354,6 @@ module Parse
|
|
357
354
|
val = [val].compact unless val.is_a?(Array)
|
358
355
|
{ @operation.operand => { key => val } }
|
359
356
|
end
|
360
|
-
|
361
357
|
end
|
362
358
|
|
363
359
|
# Equivalent to the $all Parse query operation. Checks whether the value in
|
@@ -585,7 +581,6 @@ module Parse
|
|
585
581
|
contraint_keyword :$notInQuery
|
586
582
|
register :excludes
|
587
583
|
register :not_in_query
|
588
|
-
|
589
584
|
end
|
590
585
|
|
591
586
|
# Equivalent to the `$nearSphere` Parse query operation. This is only applicable
|
@@ -631,7 +626,6 @@ module Parse
|
|
631
626
|
end
|
632
627
|
{ @operation.operand => { key => point } }
|
633
628
|
end
|
634
|
-
|
635
629
|
end
|
636
630
|
|
637
631
|
# Equivalent to the `$within` Parse query operation and `$box` geopoint
|
@@ -661,10 +655,10 @@ module Parse
|
|
661
655
|
def build
|
662
656
|
geopoint_values = formatted_value
|
663
657
|
unless geopoint_values.is_a?(Array) && geopoint_values.count == 2 &&
|
664
|
-
|
665
|
-
raise(ArgumentError,
|
666
|
-
|
667
|
-
|
658
|
+
geopoint_values.first.is_a?(Parse::GeoPoint) && geopoint_values.last.is_a?(Parse::GeoPoint)
|
659
|
+
raise(ArgumentError, "[Parse::Query] Invalid query value parameter passed to `within_box` constraint. " +
|
660
|
+
"Values in array must be `Parse::GeoPoint` objects and " +
|
661
|
+
"it should be in an array format: [southwestPoint, northeastPoint]")
|
668
662
|
end
|
669
663
|
{ @operation.operand => { :$within => { :$box => geopoint_values } } }
|
670
664
|
end
|
@@ -703,18 +697,18 @@ module Parse
|
|
703
697
|
def build
|
704
698
|
geopoint_values = formatted_value
|
705
699
|
unless geopoint_values.is_a?(Array) &&
|
706
|
-
geopoint_values.all? {|point| point.is_a?(Parse::GeoPoint) } &&
|
700
|
+
geopoint_values.all? { |point| point.is_a?(Parse::GeoPoint) } &&
|
707
701
|
geopoint_values.count > 2
|
708
|
-
raise ArgumentError,
|
709
|
-
|
710
|
-
|
702
|
+
raise ArgumentError, "[Parse::Query] Invalid query value parameter passed to" \
|
703
|
+
" `within_polygon` constraint: Value must be an array with 3" \
|
704
|
+
" or more `Parse::GeoPoint` objects"
|
711
705
|
end
|
712
706
|
|
713
707
|
{ @operation.operand => { :$geoWithin => { :$polygon => geopoint_values } } }
|
714
708
|
end
|
715
709
|
end
|
716
710
|
|
717
|
-
|
711
|
+
# Equivalent to the full text search support with `$text` with a set of search crieteria.
|
718
712
|
class FullTextSearchQueryConstraint < Constraint
|
719
713
|
# @!method text_search
|
720
714
|
# A registered method on a symbol to create the constraint. Maps to Parse
|
@@ -743,27 +737,25 @@ module Parse
|
|
743
737
|
params = { :$term => params.to_s } if params.is_a?(String) || params.is_a?(Symbol)
|
744
738
|
|
745
739
|
unless params.is_a?(Hash)
|
746
|
-
raise ArgumentError,
|
747
|
-
|
740
|
+
raise ArgumentError, "[Parse::Query] Invalid query value parameter passed to" \
|
741
|
+
" `text_search` constraint: Value must be a string or a hash of parameters."
|
748
742
|
end
|
749
743
|
|
750
|
-
params = params.inject({}) do |h,(k,v)|
|
744
|
+
params = params.inject({}) do |h, (k, v)|
|
751
745
|
u = k.to_s
|
752
|
-
u = u.columnize.prepend(
|
746
|
+
u = u.columnize.prepend("$") unless u.start_with?("$")
|
753
747
|
h[u] = v
|
754
748
|
h
|
755
749
|
end
|
756
750
|
|
757
751
|
unless params["$term"].present?
|
758
|
-
raise ArgumentError, "[Parse::Query] Invalid query value parameter passed to"\
|
759
|
-
|
760
|
-
|
752
|
+
raise ArgumentError, "[Parse::Query] Invalid query value parameter passed to" \
|
753
|
+
" `text_search` constraint: Missing required `$term` subkey.\n" \
|
754
|
+
"\tExample: #{@operation.operand}.text_search => { term: 'text to search' }"
|
761
755
|
end
|
762
756
|
|
763
757
|
{ @operation.operand => { :$text => { :$search => params } } }
|
764
758
|
end
|
765
759
|
end
|
766
|
-
|
767
760
|
end
|
768
|
-
|
769
761
|
end
|