parse-stack 1.4.3 → 1.5.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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +52 -39
  3. data/Gemfile.lock +2 -2
  4. data/README.md +609 -124
  5. data/bin/console +0 -9
  6. data/lib/parse/api/all.rb +3 -0
  7. data/lib/parse/api/analytics.rb +2 -2
  8. data/lib/parse/api/apps.rb +15 -17
  9. data/lib/parse/api/batch.rb +4 -1
  10. data/lib/parse/api/cloud_functions.rb +2 -0
  11. data/lib/parse/api/config.rb +14 -2
  12. data/lib/parse/api/files.rb +6 -3
  13. data/lib/parse/api/hooks.rb +4 -4
  14. data/lib/parse/api/objects.rb +14 -11
  15. data/lib/parse/api/push.rb +4 -2
  16. data/lib/parse/api/schemas.rb +6 -5
  17. data/lib/parse/api/sessions.rb +11 -1
  18. data/lib/parse/api/users.rb +65 -15
  19. data/lib/parse/client/authentication.rb +4 -2
  20. data/lib/parse/client/body_builder.rb +11 -3
  21. data/lib/parse/client/caching.rb +17 -6
  22. data/lib/parse/client/protocol.rb +14 -8
  23. data/lib/parse/client/request.rb +4 -1
  24. data/lib/parse/client/response.rb +59 -6
  25. data/lib/parse/client.rb +72 -42
  26. data/lib/parse/model/acl.rb +22 -4
  27. data/lib/parse/model/associations/belongs_to.rb +22 -10
  28. data/lib/parse/model/associations/collection_proxy.rb +14 -1
  29. data/lib/parse/model/associations/has_many.rb +76 -15
  30. data/lib/parse/model/associations/has_one.rb +69 -0
  31. data/lib/parse/model/associations/pointer_collection_proxy.rb +13 -6
  32. data/lib/parse/model/associations/relation_collection_proxy.rb +5 -2
  33. data/lib/parse/model/bytes.rb +6 -2
  34. data/lib/parse/model/classes/installation.rb +27 -0
  35. data/lib/parse/model/classes/role.rb +20 -0
  36. data/lib/parse/model/classes/session.rb +26 -0
  37. data/lib/parse/model/classes/user.rb +185 -0
  38. data/lib/parse/model/core/actions.rb +40 -26
  39. data/lib/parse/model/core/properties.rb +126 -20
  40. data/lib/parse/model/core/querying.rb +63 -3
  41. data/lib/parse/model/core/schema.rb +9 -6
  42. data/lib/parse/model/date.rb +5 -1
  43. data/lib/parse/model/file.rb +12 -9
  44. data/lib/parse/model/geopoint.rb +6 -4
  45. data/lib/parse/model/model.rb +29 -21
  46. data/lib/parse/model/object.rb +29 -76
  47. data/lib/parse/model/pointer.rb +8 -6
  48. data/lib/parse/model/push.rb +4 -1
  49. data/lib/parse/query/constraint.rb +3 -0
  50. data/lib/parse/query/constraints.rb +6 -3
  51. data/lib/parse/query/operation.rb +3 -0
  52. data/lib/parse/query/ordering.rb +3 -0
  53. data/lib/parse/query.rb +85 -38
  54. data/lib/parse/stack/generators/rails.rb +3 -0
  55. data/lib/parse/stack/railtie.rb +2 -0
  56. data/lib/parse/stack/tasks.rb +4 -1
  57. data/lib/parse/stack/version.rb +4 -1
  58. data/lib/parse/stack.rb +3 -0
  59. data/lib/parse/webhooks/payload.rb +14 -8
  60. data/lib/parse/webhooks/registration.rb +11 -8
  61. data/lib/parse/webhooks.rb +11 -8
  62. data/lib/parse-stack.rb +3 -0
  63. data/parse-stack.gemspec +10 -8
  64. metadata +16 -4
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'active_model'
2
5
  require 'active_support'
3
6
  require 'active_support/inflector'
@@ -21,6 +24,7 @@ require_relative 'core/actions'
21
24
  require_relative 'core/querying'
22
25
  require_relative "core/schema"
23
26
  require_relative "core/properties"
27
+ require_relative "associations/has_one"
24
28
  require_relative "associations/belongs_to"
25
29
  require_relative "associations/has_many"
26
30
 
@@ -87,16 +91,18 @@ module Parse
87
91
 
88
92
  class Object < Pointer
89
93
  include Properties
94
+ include Associations::HasOne
90
95
  include Associations::BelongsTo
91
96
  include Associations::HasMany
92
97
  include Querying
93
98
  include Fetching
94
99
  include Actions
95
100
  include Schema
101
+ BASE_OBJECT_CLASS = "Parse::Object".freeze # used for comparison
96
102
 
97
103
  def __type; Parse::Model::TYPE_OBJECT; end;
98
104
  # These define callbacks
99
- define_model_callbacks :save, :destroy
105
+ define_model_callbacks :create, :save, :destroy, only: [:after, :before]
100
106
  #core attributes. In general these should be treated as read_only, but the
101
107
  # setters are available since we will be decoding objects from Parse. The :acl
102
108
  # type is documented in its own class file.
@@ -141,7 +147,7 @@ module Parse
141
147
  elsif opts.is_a?(Hash)
142
148
  #if the objectId is provided we will consider the object pristine
143
149
  #and not track dirty items
144
- dirty_track = opts["objectId".freeze] || opts[:objectId] || opts[:id]
150
+ dirty_track = opts[Parse::Model::OBJECT_ID] || opts[:objectId] || opts[:id]
145
151
  apply_attributes!(opts, dirty_track: !dirty_track)
146
152
  end
147
153
 
@@ -211,6 +217,7 @@ module Parse
211
217
  remote_field = self.field_map[key.to_sym] || key
212
218
  h[remote_field] = send key
213
219
  # make an exception to Parse::Objects, we should return a pointer to them instead
220
+ h[remote_field] = h[remote_field].parse_pointers if h[remote_field].is_a?(Parse::PointerCollectionProxy)
214
221
  h[remote_field] = h[remote_field].pointer if h[remote_field].respond_to?(:pointer)
215
222
  end
216
223
  h
@@ -221,10 +228,18 @@ module Parse
221
228
  restore_attributes
222
229
  end
223
230
 
231
+ # overrides ActiveModel::Validations validate! instance method
232
+ # if it fails, it raises ActiveModel::ValidationError
233
+ # otherwise return self instead of true
234
+ def validate!
235
+ super
236
+ self
237
+ end
238
+
224
239
  # Returns a twin copy of the object without the objectId
225
240
  def twin
226
241
  h = self.as_json
227
- h.delete("objectId")
242
+ h.delete(Parse::Model::OBJECT_ID)
228
243
  h.delete(:objectId)
229
244
  h.delete(:id)
230
245
  self.class.new h
@@ -246,10 +261,11 @@ module Parse
246
261
  # will be returned instead.
247
262
  def self.build(json, table = nil)
248
263
  className = table
249
- className ||= (json["className"] || json[:className]) if json.is_a?(Hash)
264
+ className ||= (json[Parse::Model::KEY_CLASS_NAME] || json[:className]) if json.is_a?(Hash)
250
265
  if json.is_a?(Hash) && json["error"].present? && json["code"].present?
251
266
  warn "[Parse::Object] Detected object hash with 'error' and 'code' set. : #{json}"
252
267
  end
268
+ className = parse_class unless parse_class == BASE_OBJECT_CLASS
253
269
  return if className.nil?
254
270
  # we should do a reverse lookup on who is registered for a different class type
255
271
  # than their name with parse_class
@@ -260,7 +276,7 @@ module Parse
260
276
  # we are considering these objects as "pristine"
261
277
  o = klass.new(json)
262
278
  else
263
- o = Parse::Pointer.new className, (json["objectId"] || json[:objectId])
279
+ o = Parse::Pointer.new className, (json[Parse::Model::OBJECT_ID] || json[:objectId])
264
280
  end
265
281
  return o
266
282
  # rescue NameError => e
@@ -287,86 +303,17 @@ module Parse
287
303
  @updated_at.to_time.utc.iso8601(3) if @updated_at.present?
288
304
  end
289
305
 
290
-
291
-
292
- end
293
-
294
- # The User class provided by Parse with the required fields. You may
295
- # add mixings to this class to add the app specific properties
296
- class User < Parse::Object
297
- parse_class "_User".freeze
298
- property :auth_data, :object
299
- property :email
300
- property :password
301
- property :username
302
-
303
- before_save do
304
- # You cannot specify user ACLs.
305
- self.clear_attribute_change!(:acl)
306
- end
307
-
308
- def anonymous?
309
- auth_data.present? && auth_data["anonymous"].present?
310
- end
311
- end
312
-
313
- class Installation < Parse::Object
314
- parse_class "_Installation".freeze
315
-
316
- property :gcm_sender_id, :string, field: :GCMSenderId
317
- property :app_identifier
318
- property :app_name
319
- property :app_version
320
- property :badge, :integer
321
- property :channels, :array
322
- property :device_token
323
- property :device_token_last_modified, :integer
324
- property :device_type
325
- property :installation_id
326
- property :locale_identifier
327
- property :parse_version
328
- property :push_type
329
- property :time_zone
330
-
331
- end
332
-
333
- class Role < Parse::Object
334
- parse_class "_Role".freeze
335
- property :name
336
-
337
- has_many :roles, through: :relation
338
- has_many :users, through: :relation
339
-
340
- def update_acl
341
- acl.everyone true, false
342
- end
343
-
344
- before_save do
345
- update_acl
346
- end
347
- end
348
-
349
- class Session < Parse::Object
350
- parse_class "_Session".freeze
351
- property :created_with, :object
352
- property :expires_at, :date
353
- property :installation_id
354
- property :restricted, :boolean
355
- property :session_token
356
-
357
- belongs_to :user
358
306
  end
359
307
 
360
308
  end
361
309
 
362
-
363
310
  class Array
364
311
  # This helper method selects all objects in an array that are either inherit from
365
312
  # Parse::Pointer or are a hash. If it is a hash, a Pare::Object will be built from it
366
313
  # if it constains the proper fields. Non convertible objects will be removed
367
314
  # If the className is not contained or known, you can pass a table name as an argument
368
315
  def parse_objects(table = nil)
369
- f = "className".freeze
316
+ f = Parse::Model::KEY_CLASS_NAME
370
317
  map do |m|
371
318
  next m if m.is_a?(Parse::Pointer)
372
319
  if m.is_a?(Hash) && (m[f] || m[:className] || table)
@@ -377,7 +324,13 @@ class Array
377
324
  end
378
325
 
379
326
  def parse_ids
380
- parse_objects.map { |d| d.id }
327
+ parse_objects.map(&:id)
381
328
  end
382
329
 
383
330
  end
331
+
332
+ # Load all the core classes.
333
+ require_relative 'classes/installation'
334
+ require_relative 'classes/role'
335
+ require_relative 'classes/session'
336
+ require_relative 'classes/user'
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'active_model'
2
5
  require 'active_support'
3
6
  require 'active_support/inflector'
@@ -13,10 +16,10 @@ module Parse
13
16
  # based on your Parse application tables - however they are used for when a class is found that cannot be
14
17
  # associated with a defined ruby class or used when specifically saving Parse relation types.
15
18
  class Pointer < Model
16
-
19
+ ATTRIBUTES = { __type: :string, className: :string, objectId: :string}.freeze
17
20
  attr_accessor :parse_class, :id
18
21
 
19
- def __type; "Pointer".freeze; end;
22
+ def __type; "Pointer"; end;
20
23
  alias_method :className, :parse_class
21
24
  # A Parse object as a className field and objectId. In ruby, we will use the
22
25
  # id attribute method, but for usability, we will also alias it to objectId
@@ -32,10 +35,9 @@ module Parse
32
35
  end
33
36
 
34
37
  def attributes
35
- { __type: :string, className: :string, objectId: :string}.freeze
38
+ ATTRIBUTES
36
39
  end
37
40
 
38
-
39
41
  def json_hash
40
42
  JSON.parse to_json
41
43
  end
@@ -98,8 +100,8 @@ class Array
98
100
  #if its an exact Parse::Pointer
99
101
  if m.is_a?(Parse::Pointer) || m.respond_to?(:pointer)
100
102
  next m.pointer
101
- elsif m.is_a?(Hash) && m["className"] && m["objectId"]
102
- next Parse::Pointer.new m["className"], m["objectId"]
103
+ elsif m.is_a?(Hash) && m[Parse::Model::KEY_CLASS_NAME] && m[Parse::Model::OBJECT_ID]
104
+ next Parse::Pointer.new m[Parse::Model::KEY_CLASS_NAME], m[Parse::Model::OBJECT_ID]
103
105
  elsif m.is_a?(Hash) && m[:className] && m[:objectId]
104
106
  next Parse::Pointer.new m[:className], m[:objectId]
105
107
  end
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  require_relative '../query.rb'
2
5
  require_relative '../client.rb'
3
6
  require 'active_model_serializers'
@@ -57,7 +60,7 @@ module Parse
57
60
  msg = {
58
61
  data: {
59
62
  alert: alert,
60
- badge: badge || "Increment".freeze
63
+ badge: badge || "Increment"
61
64
  }
62
65
  }
63
66
  msg[:data][:sound] = sound if sound.present?
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  require_relative 'operation'
2
5
  require 'time'
3
6
  # Constraints are the heart of the Parse::Query system.
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  require_relative 'constraint'
2
5
 
3
6
  # Eac constraint type is a subclass of Parse::Constraint
@@ -7,7 +10,7 @@ require_relative 'constraint'
7
10
  # For more information: https://parse.com/docs/rest/guide#queries
8
11
  # For more information about the query design pattern from DataMapper
9
12
  # that inspired this, see http://datamapper.org/docs/find.html
10
- class ParseConstraintError < Exception; end;
13
+ class ParseConstraintError < StandardError; end;
11
14
  module Parse
12
15
 
13
16
  class ObjectIdConstraint < Constraint
@@ -184,14 +187,14 @@ module Parse
184
187
  remote_field_name = res[:key] || remote_field_name
185
188
  query = res[:query]
186
189
  unless query.is_a?(Parse::Query)
187
- raise "Invalid Parse::Query object provided in :query field of value: #{@operation.operand}.#{$dontSelect} => #{@value}"
190
+ raise ParseConstraintError, "Invalid Parse::Query object provided in :query field of value: #{@operation.operand}.#{$dontSelect} => #{@value}"
188
191
  end
189
192
  query = query.compile(encode: false, includeClassName: true)
190
193
  elsif @value.is_a?(Parse::Query)
191
194
  # if its a query, then assume dontSelect key is the same name as operand.
192
195
  query = @value.compile(encode: false, includeClassName: true)
193
196
  else
194
- raise "Invalid `:select` query constraint. It should follow the format: :field.select => { key: 'key', query: '<Parse::Query>' }"
197
+ raise ParseConstraintError, "Invalid `:select` query constraint. It should follow the format: :field.select => { key: 'key', query: '<Parse::Query>' }"
195
198
  end
196
199
  { @operation.operand => { :$select => { key: remote_field_name, query: query } } }
197
200
  end
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'active_support'
2
5
  require 'active_support/inflector'
3
6
 
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  # Ordering is implemented similarly as constraints in which we add
2
5
  # special methods to the Symbol class. The developer can then pass one
3
6
  # or an array of fields (as symbols) and call the particular ordering
data/lib/parse/query.rb CHANGED
@@ -1,7 +1,11 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  require_relative "client"
2
5
  require_relative "query/operation"
3
6
  require_relative "query/constraints"
4
7
  require_relative "query/ordering"
8
+ require 'active_model'
5
9
  require 'active_model_serializers'
6
10
  require 'active_support'
7
11
  require 'active_support/inflector'
@@ -20,7 +24,10 @@ module Parse
20
24
  # constraints - as Parse::Constraint
21
25
 
22
26
  class Query
27
+ extend ::ActiveModel::Callbacks
23
28
  include Parse::Client::Connectable
29
+ include Enumerable
30
+ define_model_callbacks :prepare, only: [:after, :before]
24
31
  # A query needs to be tied to a Parse table name (Parse class)
25
32
  # The client object is of type Parse::Client in order to send query requests.
26
33
  # You can modify the default client being used by all Parse::Query objects by setting
@@ -87,7 +94,9 @@ module Parse
87
94
  end
88
95
 
89
96
  def initialize(table, constraints = {})
90
- raise "First parameter should be the name of the Parse class (table)" unless table.is_a?(String)
97
+ table = table.to_s.to_parse_class if table.is_a?(Symbol)
98
+ table = table.parse_class if table.respond_to?(:parse_class)
99
+ raise ArgumentError, "First parameter should be the name of the Parse class (table)" unless table.is_a?(String)
91
100
  @count = 0 #non-zero/1 implies a count query request
92
101
  @where = []
93
102
  @order = []
@@ -122,13 +131,14 @@ module Parse
122
131
  self.use_master_key = value
123
132
  elsif expression == :session
124
133
  # you can pass a session token or a Parse::Session
125
- value = value.is_a?(Parse::Session) ? value.session_token : value
134
+ value = value.respond_to?(:session_token) ? value.session_token : value
126
135
  self.session_token = value
127
136
  else
128
137
  add_constraint(expression, value)
129
138
  end
130
139
  end # each
131
- end
140
+ self #chaining
141
+ end; alias_method :query, :conditions
132
142
 
133
143
  def table=(t)
134
144
  @table = t.to_s.camelize
@@ -186,9 +196,9 @@ module Parse
186
196
  end
187
197
 
188
198
  def related_to(field, pointer)
189
- raise "Object value must be a Parse::Pointer type" unless pointer.is_a?(Parse::Pointer)
199
+ raise ArgumentError, "Object value must be a Parse::Pointer type" unless pointer.is_a?(Parse::Pointer)
190
200
  add_constraint field.to_sym.related_to, pointer
191
- self
201
+ self #chaining
192
202
  end
193
203
 
194
204
  def includes(*fields)
@@ -204,9 +214,18 @@ module Parse
204
214
  end
205
215
  alias_method :include, :includes
206
216
 
207
- def add_constraint(operator, value, opts = {})
217
+ def add_constraints(list)
218
+ list = Array.wrap(list).select { |m| m.is_a?(Parse::Constraint) }
219
+ @where = @where + list
220
+ self
221
+ end
222
+
223
+ def add_constraint(operator, value = nil, **opts)
208
224
  @where ||= []
209
- constraint = Parse::Constraint.create operator, value
225
+ constraint = operator # assume Parse::Constraint
226
+ unless constraint.is_a?(Parse::Constraint)
227
+ constraint = Parse::Constraint.create(operator, value)
228
+ end
210
229
  return unless constraint.is_a?(Parse::Constraint)
211
230
  # to support select queries where you have to pass a `key` parameter for matching
212
231
  # different tables.
@@ -222,7 +241,10 @@ module Parse
222
241
  @results = nil
223
242
  self #chaining
224
243
  end
225
- def constraints; @where; end;
244
+
245
+ def constraints
246
+ @where
247
+ end
226
248
 
227
249
  def where(conditions = nil, opts = {})
228
250
  return @where if conditions.nil?
@@ -231,7 +253,7 @@ module Parse
231
253
  add_constraint(operator, value, opts)
232
254
  end
233
255
  end
234
- self #chaining
256
+ self #chaining
235
257
  end
236
258
 
237
259
  def or_where(where_clauses = [])
@@ -256,17 +278,16 @@ module Parse
256
278
  end
257
279
 
258
280
  def |(other_query)
259
- raise "Parse queries must be of the same class #{@table}." unless @table == other_query.table
281
+ raise ArgumentError, "Parse queries must be of the same class #{@table}." unless @table == other_query.table
260
282
  copy_query = self.clone
261
283
  copy_query.or_where other_query.where
262
284
  copy_query
263
285
  end
264
286
 
265
287
  def count
266
- @results = nil
267
288
  old_value = @count
268
289
  @count = 1
269
- res = client.find_objects(@table, compile.as_json ).count
290
+ res = client.find_objects(@table, compile.as_json, _opts ).count
270
291
  @count = old_value
271
292
  res
272
293
  end
@@ -276,8 +297,27 @@ module Parse
276
297
  results.each(&Proc.new)
277
298
  end
278
299
 
300
+ def map
301
+ return results.enum_for(:map) unless block_given? # Sparkling magic!
302
+ results.map(&Proc.new)
303
+ end
304
+
305
+ def select
306
+ return results.enum_for(:select) unless block_given? # Sparkling magic!
307
+ results.select(&Proc.new)
308
+ end
309
+
310
+ def to_a
311
+ results.to_a
312
+ end
313
+
314
+ def select
315
+ return results.enum_for(:select) unless block_given? # Sparkling magic!
316
+ results.select(&Proc.new)
317
+ end
318
+
279
319
  def first(limit = 1)
280
- @results = nil
320
+ @results = nil if @limit != limit
281
321
  @limit = limit
282
322
  limit == 1 ? results.first : results.first(limit)
283
323
  end
@@ -313,22 +353,27 @@ module Parse
313
353
  results
314
354
  end
315
355
 
316
- def fetch!(compiled_query)
356
+ def _opts
317
357
  opts = {}
318
358
  opts[:cache] = self.cache || false
319
359
  opts[:use_master_key] = self.use_master_key
320
360
  opts[:session_token] = self.session_token
321
361
  # for now, don't cache requests where we disable master_key or provide session token
322
- if opts[:use_master_key] == false || opts[:session_token].present?
323
- opts[:cache] = false
324
- end
362
+ # if opts[:use_master_key] == false || opts[:session_token].present?
363
+ # opts[:cache] = false
364
+ # end
365
+ opts
366
+ end
367
+
368
+ def fetch!(compiled_query)
325
369
 
326
- response = client.find_objects(@table, compiled_query.as_json, opts )
370
+ response = client.find_objects(@table, compiled_query.as_json, _opts )
327
371
  if response.error?
328
372
  puts "[ParseQuery] #{response.error}"
329
373
  end
330
374
  response
331
375
  end
376
+ alias_method :execute!, :fetch!
332
377
 
333
378
  def results(raw: false)
334
379
  if @results.nil?
@@ -361,28 +406,30 @@ module Parse
361
406
  end
362
407
 
363
408
  def compile(encode: true, includeClassName: false)
364
- q = {} #query
365
- q[:limit] = 11_000 if @limit == :max || @limit == :all
366
- q[:limit] = @limit if @limit.is_a?(Numeric) && @limit > 0
367
- q[:skip] = @skip if @skip > 0
368
-
369
- q[:include] = @includes.join(',') unless @includes.empty?
370
- q[:keys] = @keys.join(',') unless @keys.empty?
371
- q[:order] = @order.join(',') unless @order.empty?
372
- unless @where.empty?
373
- q[:where] = Parse::Query.compile_where(@where)
374
- q[:where] = q[:where].to_json if encode
375
- end
409
+ run_callbacks :prepare do
410
+ q = {} #query
411
+ q[:limit] = 11_000 if @limit == :max || @limit == :all
412
+ q[:limit] = @limit if @limit.is_a?(Numeric) && @limit > 0
413
+ q[:skip] = @skip if @skip > 0
414
+
415
+ q[:include] = @includes.join(',') unless @includes.empty?
416
+ q[:keys] = @keys.join(',') unless @keys.empty?
417
+ q[:order] = @order.join(',') unless @order.empty?
418
+ unless @where.empty?
419
+ q[:where] = Parse::Query.compile_where(@where)
420
+ q[:where] = q[:where].to_json if encode
421
+ end
376
422
 
377
- if @count && @count > 0
378
- # if count is requested
379
- q[:limit] = 0
380
- q[:count] = 1
381
- end
382
- if includeClassName
383
- q[:className] = @table
423
+ if @count && @count > 0
424
+ # if count is requested
425
+ q[:limit] = 0
426
+ q[:count] = 1
427
+ end
428
+ if includeClassName
429
+ q[:className] = @table
430
+ end
431
+ q
384
432
  end
385
- q
386
433
  end
387
434
 
388
435
  def compile_where
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'parse/stack'
2
5
  require 'parse/stack/tasks'
3
6
  require 'rails/generators'
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
1
3
 
2
4
  module Parse
3
5
  module Stack
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  require_relative '../stack.rb'
2
5
  require 'active_support'
3
6
  require 'active_support/inflector'
@@ -44,7 +47,7 @@ module Parse
44
47
 
45
48
  task :verify_env => :env do
46
49
 
47
- unless Parse::Client.session?
50
+ unless Parse::Client.client?
48
51
  raise "Please make sure you have setup the Parse.setup configuration before invoking task. Usually done in the :environment task."
49
52
  end
50
53
 
@@ -1,5 +1,8 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  module Parse
2
5
  module Stack
3
- VERSION = "1.4.3"
6
+ VERSION = "1.5.1"
4
7
  end
5
8
  end
data/lib/parse/stack.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  require_relative "stack/version"
2
5
  require_relative 'client'
3
6
  require_relative 'query'
@@ -1,3 +1,6 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
1
4
  require 'active_model'
2
5
  require 'active_support'
3
6
  require 'active_support/inflector'
@@ -9,6 +12,11 @@ require 'active_model_serializers'
9
12
  module Parse
10
13
 
11
14
  class Payload
15
+ ATTRIBUTES = { master: nil, user: nil,
16
+ installationId: nil, params: nil,
17
+ functionName: nil, object: nil,
18
+ original: nil, update: nil,
19
+ triggerName: nil }.freeze
12
20
  include ::ActiveModel::Serializers::JSON
13
21
  attr_accessor :master, :user, :installation_id, :params, :function_name, :object, :trigger_name
14
22
 
@@ -32,18 +40,22 @@ module Parse
32
40
  @update = hash[:update] || {} #it comes as an update hash
33
41
  end
34
42
 
43
+ def attributes
44
+ ATTRIBUTES
45
+ end
46
+
35
47
  def function?
36
48
  @function_name.present?
37
49
  end
38
50
 
39
51
  def parse_class
40
52
  return nil unless @object.present?
41
- @object["className".freeze] || @object[:className]
53
+ @object[Parse::Model::KEY_CLASS_NAME] || @object[:className]
42
54
  end
43
55
 
44
56
  def parse_id
45
57
  return nil unless @object.present?
46
- @object["objectId".freeze] || @object[:objectId]
58
+ @object[Parse::Model::OBJECT_ID] || @object[:objectId]
47
59
  end; alias_method :objectId, :parse_id
48
60
 
49
61
  def trigger?
@@ -117,12 +129,6 @@ module Parse
117
129
  Parse::Object.build(@object)
118
130
  end
119
131
 
120
-
121
- def attributes
122
- { master: nil, user: nil, installationId: nil, params: nil,
123
- functionName: nil, object: nil, original: nil, update: nil, triggerName: nil }.freeze
124
- end
125
-
126
132
  end # Payload
127
133
 
128
134
  end