parse-stack 1.7.3 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +36 -0
  3. data/.solargraph.yml +23 -0
  4. data/.travis.yml +6 -3
  5. data/Changes.md +84 -22
  6. data/Gemfile +14 -12
  7. data/Gemfile.lock +110 -60
  8. data/README.md +67 -24
  9. data/Rakefile +14 -14
  10. data/bin/parse-console +1 -0
  11. data/lib/parse/api/aggregate.rb +59 -0
  12. data/lib/parse/api/all.rb +2 -1
  13. data/lib/parse/api/analytics.rb +0 -3
  14. data/lib/parse/api/batch.rb +3 -5
  15. data/lib/parse/api/cloud_functions.rb +0 -3
  16. data/lib/parse/api/config.rb +0 -4
  17. data/lib/parse/api/files.rb +3 -7
  18. data/lib/parse/api/hooks.rb +4 -8
  19. data/lib/parse/api/objects.rb +9 -14
  20. data/lib/parse/api/push.rb +0 -4
  21. data/lib/parse/api/schema.rb +2 -6
  22. data/lib/parse/api/server.rb +4 -7
  23. data/lib/parse/api/sessions.rb +2 -5
  24. data/lib/parse/api/users.rb +9 -14
  25. data/lib/parse/client.rb +55 -50
  26. data/lib/parse/client/authentication.rb +29 -33
  27. data/lib/parse/client/batch.rb +8 -11
  28. data/lib/parse/client/body_builder.rb +19 -20
  29. data/lib/parse/client/caching.rb +23 -28
  30. data/lib/parse/client/protocol.rb +11 -12
  31. data/lib/parse/client/request.rb +4 -6
  32. data/lib/parse/client/response.rb +5 -7
  33. data/lib/parse/model/acl.rb +14 -12
  34. data/lib/parse/model/associations/belongs_to.rb +19 -24
  35. data/lib/parse/model/associations/collection_proxy.rb +328 -317
  36. data/lib/parse/model/associations/has_many.rb +22 -27
  37. data/lib/parse/model/associations/has_one.rb +7 -12
  38. data/lib/parse/model/associations/pointer_collection_proxy.rb +5 -13
  39. data/lib/parse/model/associations/relation_collection_proxy.rb +5 -9
  40. data/lib/parse/model/bytes.rb +8 -10
  41. data/lib/parse/model/classes/installation.rb +2 -4
  42. data/lib/parse/model/classes/product.rb +2 -5
  43. data/lib/parse/model/classes/role.rb +3 -5
  44. data/lib/parse/model/classes/session.rb +2 -5
  45. data/lib/parse/model/classes/user.rb +21 -17
  46. data/lib/parse/model/core/actions.rb +31 -46
  47. data/lib/parse/model/core/builder.rb +6 -6
  48. data/lib/parse/model/core/errors.rb +0 -1
  49. data/lib/parse/model/core/fetching.rb +45 -50
  50. data/lib/parse/model/core/properties.rb +53 -68
  51. data/lib/parse/model/core/querying.rb +292 -282
  52. data/lib/parse/model/core/schema.rb +89 -92
  53. data/lib/parse/model/date.rb +16 -23
  54. data/lib/parse/model/file.rb +171 -174
  55. data/lib/parse/model/geopoint.rb +12 -16
  56. data/lib/parse/model/model.rb +31 -37
  57. data/lib/parse/model/object.rb +58 -70
  58. data/lib/parse/model/pointer.rb +177 -176
  59. data/lib/parse/model/push.rb +8 -10
  60. data/lib/parse/model/shortnames.rb +1 -2
  61. data/lib/parse/model/time_zone.rb +3 -5
  62. data/lib/parse/query.rb +70 -37
  63. data/lib/parse/query/constraint.rb +4 -6
  64. data/lib/parse/query/constraints.rb +62 -20
  65. data/lib/parse/query/operation.rb +8 -11
  66. data/lib/parse/query/ordering.rb +45 -49
  67. data/lib/parse/stack.rb +15 -11
  68. data/lib/parse/stack/generators/rails.rb +28 -30
  69. data/lib/parse/stack/generators/templates/model.erb +5 -6
  70. data/lib/parse/stack/generators/templates/model_installation.rb +0 -1
  71. data/lib/parse/stack/generators/templates/model_role.rb +0 -1
  72. data/lib/parse/stack/generators/templates/model_session.rb +0 -1
  73. data/lib/parse/stack/generators/templates/model_user.rb +0 -1
  74. data/lib/parse/stack/generators/templates/parse.rb +9 -9
  75. data/lib/parse/stack/generators/templates/webhooks.rb +1 -2
  76. data/lib/parse/stack/railtie.rb +2 -4
  77. data/lib/parse/stack/tasks.rb +70 -86
  78. data/lib/parse/stack/version.rb +1 -1
  79. data/lib/parse/webhooks.rb +19 -26
  80. data/lib/parse/webhooks/payload.rb +26 -28
  81. data/lib/parse/webhooks/registration.rb +23 -31
  82. data/parse-stack.gemspec +28 -28
  83. data/parse-stack.png +0 -0
  84. metadata +27 -25
  85. data/.github/parse-ruby-sdk.png +0 -0
@@ -1,13 +1,12 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative '../pointer'
5
- require_relative 'collection_proxy'
6
- require_relative 'pointer_collection_proxy'
7
- require_relative 'relation_collection_proxy'
4
+ require_relative "../pointer"
5
+ require_relative "collection_proxy"
6
+ require_relative "pointer_collection_proxy"
7
+ require_relative "relation_collection_proxy"
8
8
 
9
9
  module Parse
10
-
11
10
  module Associations
12
11
 
13
12
  # Parse has many ways to implement one-to-many and many-to-many
@@ -325,9 +324,11 @@ module Parse
325
324
  # @!visibility private
326
325
  module ClassMethods
327
326
  attr_accessor :relations
327
+
328
328
  def relations
329
329
  @relations ||= {}
330
330
  end
331
+
331
332
  # Examples:
332
333
  # has_many :fans, as: :users, through: :relation, field: "awesomeFans"
333
334
  # has_many :songs
@@ -353,7 +354,7 @@ module Parse
353
354
  # the remote class is either key or as.
354
355
  opts[:scope_only] ||= false
355
356
  klassName = (opts[:as] || key).to_parse_class singularize: true
356
- foreign_field = (opts[:field] || parse_class.columnize ).to_sym
357
+ foreign_field = (opts[:field] || parse_class.columnize).to_sym
357
358
 
358
359
  define_method(key) do |*args, &block|
359
360
  return [] if @id.nil?
@@ -372,7 +373,7 @@ module Parse
372
373
  query.instance_exec(&scope)
373
374
  query.conditions(*args) if args.present?
374
375
  else
375
- query.instance_exec(*args,&scope)
376
+ query.instance_exec(*args, &scope)
376
377
  end
377
378
  instance = nil # help clean up ruby gc
378
379
  elsif args.present?
@@ -383,11 +384,10 @@ module Parse
383
384
  klass = Parse::Model.find_class klassName
384
385
 
385
386
  if klass.present? && klass.respond_to?(m)
386
-
387
387
  klass_scope = klass.send(m, *args) # blocks only passed to final result set
388
388
  return klass_scope unless klass_scope.is_a?(Parse::Query)
389
389
  # merge constraints
390
- add_constraints( klass_scope.constraints )
390
+ add_constraints(klass_scope.constraints)
391
391
  # if a block was passed, execute the query, otherwise return the query
392
392
  return chained_block.present? ? results(&chained_block) : self
393
393
  end
@@ -399,7 +399,6 @@ module Parse
399
399
  return query if block.nil?
400
400
  query.results(&block)
401
401
  end
402
-
403
402
  end
404
403
 
405
404
  # Define a one-to-many or many-to-many association between the local model and a foreign class.
@@ -412,9 +411,10 @@ module Parse
412
411
 
413
412
  # below this is the same
414
413
  opts.reverse_merge!({
415
- field: key.to_s.camelize(:lower),
416
- required: false,
417
- as: key})
414
+ field: key.to_s.camelize(:lower),
415
+ required: false,
416
+ as: key,
417
+ })
418
418
 
419
419
  klassName = opts[:as].to_parse_class singularize: true
420
420
  parse_field = opts[:field].to_sym # name of the column (local or remote)
@@ -426,10 +426,12 @@ module Parse
426
426
 
427
427
  # verify that the user did not duplicate properties or defined different properties with the same name
428
428
  if self.fields[key].present? && Parse::Properties::BASE_FIELD_MAP[key].nil?
429
- raise ArgumentError, "Has_many property #{self}##{key} already defined with type #{klassName}"
429
+ warn "Has_many property #{self}##{key} already defined with type #{klassName}"
430
+ return false
430
431
  end
431
432
  if self.fields[parse_field].present?
432
- raise ArgumentError, "Alias has_many #{self}##{parse_field} conflicts with previously defined property."
433
+ warn "Alias has_many #{self}##{parse_field} conflicts with previously defined property."
434
+ return false
433
435
  end
434
436
  # validations
435
437
  validates_presence_of(key) if opts[:required]
@@ -444,12 +446,12 @@ module Parse
444
446
  proxyKlass = Parse::RelationCollectionProxy
445
447
  self.relations[key] = klassName
446
448
  else
447
- self.attributes.merge!( parse_field => :array )
449
+ self.attributes.merge!(parse_field => :array)
448
450
  # Add them to the list of fields in our class model
449
- self.fields.merge!( key => :array, parse_field => :array )
451
+ self.fields.merge!(key => :array, parse_field => :array)
450
452
  end
451
453
 
452
- self.field_map.merge!( key => parse_field )
454
+ self.field_map.merge!(key => parse_field)
453
455
  # dirty tracking
454
456
  define_attribute_methods key
455
457
 
@@ -474,7 +476,7 @@ module Parse
474
476
 
475
477
  # proxy setter that forwards with dirty tracking
476
478
  define_method("#{key}=") do |val|
477
- send set_attribute_method, val, true
479
+ send set_attribute_method, val, true
478
480
  end
479
481
 
480
482
  # This will set the content of the proxy.
@@ -508,7 +510,7 @@ module Parse
508
510
 
509
511
  # send dirty tracking if set
510
512
  if track == true
511
- send will_change_method unless val == instance_variable_get( ivar )
513
+ send will_change_method unless val == instance_variable_get(ivar)
512
514
  end
513
515
  # TODO: Only allow empty proxy collection class as a value or nil.
514
516
  if val.is_a?(Parse::CollectionProxy)
@@ -516,7 +518,6 @@ module Parse
516
518
  else
517
519
  warn "[#{self.class}] Invalid value #{val} for :has_many field #{key}. Should be an Array or a CollectionProxy"
518
520
  end
519
-
520
521
  end
521
522
 
522
523
  data_type = opts[:through]
@@ -533,7 +534,6 @@ module Parse
533
534
  q = self.send :"#{key}_relation_query"
534
535
  q.results || []
535
536
  end
536
-
537
537
  end
538
538
 
539
539
  # if the remote field name and the local field name are the same
@@ -547,8 +547,6 @@ module Parse
547
547
  elsif parse_field.to_sym != :objectId
548
548
  warn "Alias has_many method #{self}##{parse_field} already defined."
549
549
  end
550
-
551
-
552
550
  end # has_many_array
553
551
  end #ClassMethods
554
552
 
@@ -576,9 +574,6 @@ module Parse
576
574
  def relation_changes?
577
575
  changed.any? { |key| relations[key.to_sym] }
578
576
  end
579
-
580
577
  end # HasMany
581
578
  end #Associations
582
-
583
-
584
579
  end # Parse
@@ -1,10 +1,10 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative '../pointer'
5
- require_relative 'collection_proxy'
6
- require_relative 'pointer_collection_proxy'
7
- require_relative 'relation_collection_proxy'
4
+ require_relative "../pointer"
5
+ require_relative "collection_proxy"
6
+ require_relative "pointer_collection_proxy"
7
+ require_relative "relation_collection_proxy"
8
8
 
9
9
  module Parse
10
10
  module Associations
@@ -115,14 +115,13 @@ module Parse
115
115
 
116
116
  # has one are not property but instance scope methods
117
117
  def has_one(key, scope = nil, **opts)
118
-
119
- opts.reverse_merge!({as: key, field: parse_class.columnize, scope_only: false})
118
+ opts.reverse_merge!({ as: key, field: parse_class.columnize, scope_only: false })
120
119
  klassName = opts[:as].to_parse_class
121
120
  foreign_field = opts[:field].to_sym
122
121
  ivar = :"@_has_one_#{key}"
123
122
 
124
123
  if self.method_defined?(key)
125
- puts "Creating has_one :#{key} association. Will overwrite existing method #{self}##{key}."
124
+ warn "Creating has_one :#{key} association. Will overwrite existing method #{self}##{key}."
126
125
  end
127
126
 
128
127
  define_method(key) do |*args, &block|
@@ -140,7 +139,7 @@ module Parse
140
139
  query.instance_exec(&scope)
141
140
  query.conditions(*args) if args.present?
142
141
  else
143
- query.instance_exec(*args,&scope)
142
+ query.instance_exec(*args, &scope)
144
143
  end
145
144
  instance = nil # help clean up ruby gc
146
145
  elsif args.present?
@@ -152,12 +151,8 @@ module Parse
152
151
  return query.first if block.nil?
153
152
  block.call(query.first)
154
153
  end
155
-
156
154
  end
157
-
158
155
  end
159
-
160
156
  end
161
-
162
157
  end
163
158
  end
@@ -1,12 +1,11 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'active_model'
5
- require 'active_support'
6
- require 'active_support/inflector'
7
- require 'active_support/core_ext/object'
8
- require_relative 'collection_proxy'
9
-
4
+ require "active_model"
5
+ require "active_support"
6
+ require "active_support/inflector"
7
+ require "active_support/core_ext/object"
8
+ require_relative "collection_proxy"
10
9
 
11
10
  module Parse
12
11
  # A PointerCollectionProxy is a collection proxy that only allows Parse Pointers (Objects)
@@ -101,12 +100,5 @@ module Parse
101
100
  def as_json(opts = nil)
102
101
  parse_pointers.as_json(opts)
103
102
  end
104
-
105
- # @return [Array<Parse::Pointer>] an array of pointers representing this collection.
106
- def parse_pointers
107
- collection.parse_pointers
108
- end
109
-
110
103
  end
111
-
112
104
  end
@@ -1,10 +1,10 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'active_support'
5
- require 'active_support/inflector'
6
- require 'active_support/core_ext/object'
7
- require_relative 'pointer_collection_proxy'
4
+ require "active_support"
5
+ require "active_support/inflector"
6
+ require "active_support/core_ext/object"
7
+ require_relative "pointer_collection_proxy"
8
8
 
9
9
  module Parse
10
10
  # The RelationCollectionProxy is similar to a PointerCollectionProxy except that
@@ -36,7 +36,6 @@ module Parse
36
36
  # clearing out the change information for the collection if saved successfully.
37
37
  # @see PointerCollectionProxy
38
38
  class RelationCollectionProxy < PointerCollectionProxy
39
-
40
39
  define_attribute_methods :additions, :removals
41
40
  # @!attribute [r] removals
42
41
  # The objects that have been newly removed to this collection
@@ -55,7 +54,7 @@ module Parse
55
54
  # You can get items within the collection relation filtered by a specific set
56
55
  # of query constraints.
57
56
  def all(constraints = {})
58
- q = query( {limit: :max}.merge(constraints) )
57
+ q = query({ limit: :max }.merge(constraints))
59
58
  if block_given?
60
59
  # if we have a query, then use the Proc with it (more efficient)
61
60
  return q.present? ? q.results(&Proc.new) : collection.each(&Proc.new)
@@ -69,7 +68,6 @@ module Parse
69
68
  q = forward :"#{@key}_relation_query"
70
69
  end
71
70
 
72
-
73
71
  # Add Parse::Objects to the relation.
74
72
  # @overload add(parse_object)
75
73
  # Add a Parse::Object or Parse::Pointer to this relation.
@@ -157,7 +155,5 @@ module Parse
157
155
  list.each { |d| add(d) }
158
156
  @collection
159
157
  end
160
-
161
158
  end
162
-
163
159
  end
@@ -1,24 +1,24 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'active_support'
5
- require 'active_support/core_ext/object'
4
+ require "active_support"
5
+ require "active_support/core_ext/object"
6
6
  require_relative "model"
7
- require 'base64'
8
-
7
+ require "base64"
9
8
 
10
9
  module Parse
11
10
 
12
11
  # Support for the Bytes type in Parse
13
12
  class Bytes < Model
14
13
  # The default attributes in a Parse Bytes hash.
15
- ATTRIBUTES = {__type: :string, base64: :string }.freeze
14
+ ATTRIBUTES = { __type: :string, base64: :string }.freeze
16
15
  # @return [String] the base64 string representing the content
17
16
  attr_accessor :base64
18
17
  # @return [TYPE_BYTES]
19
- def self.parse_class; TYPE_BYTES; end;
18
+ def self.parse_class; TYPE_BYTES; end
20
19
  # @return [TYPE_BYTES]
21
- def parse_class; self.class.parse_class; end;
20
+ def parse_class; self.class.parse_class; end
21
+
22
22
  alias_method :__type, :parse_class
23
23
 
24
24
  # initialize with a base64 string or a Bytes object
@@ -47,7 +47,7 @@ module Parse
47
47
 
48
48
  def attributes=(a)
49
49
  if a.is_a?(String)
50
- @bytes = a
50
+ @bytes = a
51
51
  elsif a.is_a?(Hash)
52
52
  @bytes = a["base64"] || @bytes
53
53
  end
@@ -58,7 +58,5 @@ module Parse
58
58
  return false unless u.is_a?(self.class)
59
59
  @base64 == u.base64
60
60
  end
61
-
62
61
  end
63
-
64
62
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
- require_relative '../object'
3
+ require_relative "../object"
4
4
 
5
5
  module Parse
6
6
  # This class represents the data and columns contained in the standard Parse
@@ -36,7 +36,6 @@ module Parse
36
36
  # @see Push
37
37
  # @see Parse::Object
38
38
  class Installation < Parse::Object
39
-
40
39
  parse_class Parse::Model::CLASS_INSTALLATION
41
40
  # @!attribute gcm_sender_id
42
41
  # This field only has meaning for Android installations that use the GCM
@@ -126,7 +125,6 @@ module Parse
126
125
  # This is implemented as a has_one association to the Session class using the {installation_id}.
127
126
  # @version 1.7.1
128
127
  # @return [Parse::Session] The associated {Parse::Session} that might be tied to this installation
129
- has_one :session, ->{ where(installation_id: i.installation_id) }, scope_only: true
128
+ has_one :session, -> { where(installation_id: i.installation_id) }, scope_only: true
130
129
  end
131
-
132
130
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
- require_relative '../object'
4
- require_relative 'user'
3
+ require_relative "../object"
4
+ require_relative "user"
5
5
 
6
6
  module Parse
7
7
  # This class represents the data and columns contained in the standard Parse `_Product` collection.
@@ -22,7 +22,6 @@ module Parse
22
22
  # end
23
23
  # @see Parse::Object
24
24
  class Product < Parse::Object
25
-
26
25
  parse_class Parse::Model::CLASS_PRODUCT
27
26
  # @!attribute download
28
27
  # @return [String] the file payload for this product download.
@@ -56,7 +55,5 @@ module Parse
56
55
  # The title for this product. This field is required by Parse.
57
56
  # @return [String] the title for this product.
58
57
  property :title, required: true
59
-
60
58
  end
61
-
62
59
  end
@@ -1,7 +1,8 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
- require_relative '../object'
4
- require_relative 'user'
3
+ require_relative "../object"
4
+ require_relative "user"
5
+
5
6
  module Parse
6
7
  # This class represents the data and columns contained in the standard Parse `_Role` collection.
7
8
  # Roles allow the an application to group a set of {Parse::User} records with the same set of
@@ -23,7 +24,6 @@ module Parse
23
24
  # end
24
25
  # @see Parse::Object
25
26
  class Role < Parse::Object
26
-
27
27
  parse_class Parse::Model::CLASS_ROLE
28
28
  # @!attribute name
29
29
  # @return [String] the name of this role.
@@ -37,7 +37,5 @@ module Parse
37
37
  # This attribute is mapped as a `has_many` Parse relation association with the {Parse::User} class.
38
38
  # @return [RelationCollectionProxy<User>] a Parse relation of users belonging to this role.
39
39
  has_many :users, through: :relation
40
-
41
40
  end
42
-
43
41
  end
@@ -1,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
- require_relative '../object'
3
+ require_relative "../object"
4
4
 
5
5
  module Parse
6
6
  # This class represents the data and columns contained in the standard Parse
@@ -28,7 +28,6 @@ module Parse
28
28
  #
29
29
  # @see Parse::Object
30
30
  class Session < Parse::Object
31
-
32
31
  parse_class Parse::Model::CLASS_SESSION
33
32
 
34
33
  # @!attribute created_with
@@ -63,7 +62,7 @@ module Parse
63
62
  # in the {Parse::Installation} collection. This is implemented as a has_one scope.
64
63
  # @version 1.7.1
65
64
  # @return [Parse::Installation] The associated {Parse::Installation} tied to this session
66
- has_one :installation, ->{ where(installation_id: i.installation_id) }, scope_only: true
65
+ has_one :installation, -> { where(installation_id: i.installation_id) }, scope_only: true
67
66
 
68
67
  # Return the Session record for this session token.
69
68
  # @param token [String] the session token
@@ -75,7 +74,5 @@ module Parse
75
74
  end
76
75
  nil
77
76
  end
78
-
79
77
  end
80
-
81
78
  end