parse-stack 1.8.0 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.solargraph.yml +23 -0
  3. data/.travis.yml +0 -1
  4. data/Gemfile +13 -12
  5. data/Gemfile.lock +88 -51
  6. data/README.md +2 -4
  7. data/Rakefile +14 -14
  8. data/lib/parse/api/aggregate.rb +4 -7
  9. data/lib/parse/api/all.rb +1 -1
  10. data/lib/parse/api/analytics.rb +0 -3
  11. data/lib/parse/api/batch.rb +3 -5
  12. data/lib/parse/api/cloud_functions.rb +0 -3
  13. data/lib/parse/api/config.rb +0 -4
  14. data/lib/parse/api/files.rb +3 -7
  15. data/lib/parse/api/hooks.rb +4 -8
  16. data/lib/parse/api/objects.rb +7 -12
  17. data/lib/parse/api/push.rb +0 -4
  18. data/lib/parse/api/schema.rb +2 -6
  19. data/lib/parse/api/server.rb +4 -7
  20. data/lib/parse/api/sessions.rb +2 -5
  21. data/lib/parse/api/users.rb +9 -14
  22. data/lib/parse/client.rb +54 -50
  23. data/lib/parse/client/authentication.rb +29 -33
  24. data/lib/parse/client/batch.rb +8 -11
  25. data/lib/parse/client/body_builder.rb +19 -20
  26. data/lib/parse/client/caching.rb +23 -28
  27. data/lib/parse/client/protocol.rb +11 -12
  28. data/lib/parse/client/request.rb +4 -6
  29. data/lib/parse/client/response.rb +5 -7
  30. data/lib/parse/model/acl.rb +14 -12
  31. data/lib/parse/model/associations/belongs_to.rb +14 -21
  32. data/lib/parse/model/associations/collection_proxy.rb +328 -329
  33. data/lib/parse/model/associations/has_many.rb +18 -25
  34. data/lib/parse/model/associations/has_one.rb +6 -11
  35. data/lib/parse/model/associations/pointer_collection_proxy.rb +5 -8
  36. data/lib/parse/model/associations/relation_collection_proxy.rb +5 -9
  37. data/lib/parse/model/bytes.rb +8 -10
  38. data/lib/parse/model/classes/installation.rb +2 -4
  39. data/lib/parse/model/classes/product.rb +2 -5
  40. data/lib/parse/model/classes/role.rb +3 -5
  41. data/lib/parse/model/classes/session.rb +2 -5
  42. data/lib/parse/model/classes/user.rb +20 -16
  43. data/lib/parse/model/core/actions.rb +31 -46
  44. data/lib/parse/model/core/builder.rb +6 -6
  45. data/lib/parse/model/core/errors.rb +0 -1
  46. data/lib/parse/model/core/fetching.rb +45 -50
  47. data/lib/parse/model/core/properties.rb +51 -66
  48. data/lib/parse/model/core/querying.rb +291 -294
  49. data/lib/parse/model/core/schema.rb +89 -92
  50. data/lib/parse/model/date.rb +16 -17
  51. data/lib/parse/model/file.rb +171 -174
  52. data/lib/parse/model/geopoint.rb +12 -16
  53. data/lib/parse/model/model.rb +31 -37
  54. data/lib/parse/model/object.rb +47 -53
  55. data/lib/parse/model/pointer.rb +177 -176
  56. data/lib/parse/model/push.rb +8 -10
  57. data/lib/parse/model/shortnames.rb +1 -2
  58. data/lib/parse/model/time_zone.rb +3 -5
  59. data/lib/parse/query.rb +34 -35
  60. data/lib/parse/query/constraint.rb +4 -6
  61. data/lib/parse/query/constraints.rb +21 -29
  62. data/lib/parse/query/operation.rb +8 -11
  63. data/lib/parse/query/ordering.rb +45 -49
  64. data/lib/parse/stack.rb +11 -12
  65. data/lib/parse/stack/generators/rails.rb +28 -30
  66. data/lib/parse/stack/generators/templates/model.erb +5 -6
  67. data/lib/parse/stack/generators/templates/model_installation.rb +0 -1
  68. data/lib/parse/stack/generators/templates/model_role.rb +0 -1
  69. data/lib/parse/stack/generators/templates/model_session.rb +0 -1
  70. data/lib/parse/stack/generators/templates/model_user.rb +0 -1
  71. data/lib/parse/stack/generators/templates/parse.rb +9 -9
  72. data/lib/parse/stack/generators/templates/webhooks.rb +1 -2
  73. data/lib/parse/stack/railtie.rb +2 -4
  74. data/lib/parse/stack/tasks.rb +70 -86
  75. data/lib/parse/stack/version.rb +1 -1
  76. data/lib/parse/webhooks.rb +19 -26
  77. data/lib/parse/webhooks/payload.rb +26 -28
  78. data/lib/parse/webhooks/registration.rb +23 -31
  79. data/parse-stack.gemspec +25 -25
  80. data/parse-stack.png +0 -0
  81. metadata +13 -7
  82. data/.github/parse-ruby-sdk.png +0 -0
@@ -24,7 +24,7 @@ module Parse
24
24
  #
25
25
  class GeoPoint < Model
26
26
  # The default attributes in a Parse GeoPoint hash.
27
- ATTRIBUTES = { __type: :string, latitude: :float, longitude: :float }.freeze
27
+ ATTRIBUTES = { __type: :string, latitude: :float, longitude: :float }.freeze
28
28
 
29
29
  # @return [Float] latitude value between -90.0 and 90.0
30
30
  attr_accessor :latitude
@@ -47,9 +47,10 @@ module Parse
47
47
  alias_method :lat, :latitude
48
48
  alias_method :lng, :longitude
49
49
  # @return [Model::TYPE_GEOPOINT]
50
- def self.parse_class; TYPE_GEOPOINT; end;
50
+ def self.parse_class; TYPE_GEOPOINT; end
51
51
  # @return [Model::TYPE_GEOPOINT]
52
- def parse_class; self.class.parse_class; end;
52
+ def parse_class; self.class.parse_class; end
53
+
53
54
  alias_method :__type, :parse_class
54
55
 
55
56
  # The initializer can create a GeoPoint with a hash, array or values.
@@ -77,7 +78,6 @@ module Parse
77
78
 
78
79
  # @!visibility private
79
80
  def _validate_point
80
-
81
81
  unless @latitude.nil? || @latitude.between?(LAT_MIN, LAT_MAX)
82
82
  warn "[Parse::GeoPoint] Latitude (#{@latitude}) is not between #{LAT_MIN}, #{LAT_MAX}!"
83
83
  warn "Attempting to use GeoPoint’s with latitudes outside these ranges will raise an exception in a future release."
@@ -87,7 +87,6 @@ module Parse
87
87
  warn "[Parse::GeoPoint] Longitude (#{@longitude}) is not between #{LNG_MIN}, #{LNG_MAX}!"
88
88
  warn "Attempting to use GeoPoint’s with longitude outside these ranges will raise an exception in a future release."
89
89
  end
90
-
91
90
  end
92
91
 
93
92
  # @return [Hash] attributes for a Parse GeoPoint.
@@ -99,7 +98,7 @@ module Parse
99
98
  # @return [Array] containing [lat,lng,miles]
100
99
  def max_miles(m)
101
100
  m = 0 if m.nil?
102
- [@latitude,@longitude,m]
101
+ [@latitude, @longitude, m]
103
102
  end
104
103
 
105
104
  def latitude=(l)
@@ -118,7 +117,7 @@ module Parse
118
117
  if h.is_a?(Hash)
119
118
  h = h.symbolize_keys
120
119
  @latitude = h[:latitude].to_f || h[:lat].to_f || @latitude
121
- @longitude = h[:longitude].to_f || h[:lng].to_f || @longitude
120
+ @longitude = h[:longitude].to_f || h[:lng].to_f || @longitude
122
121
  elsif h.is_a?(Array) && h.count == 2
123
122
  @latitude = h.first.to_f
124
123
  @longitude = h.last.to_f
@@ -142,7 +141,7 @@ module Parse
142
141
  # Returns a tuple containing latitude and longitude
143
142
  # @return [Array]
144
143
  def to_a
145
- [@latitude,@longitude]
144
+ [@latitude, @longitude]
146
145
  end
147
146
 
148
147
  # @!visibility private
@@ -161,7 +160,7 @@ module Parse
161
160
  # is longitude instead of a GeoPoint.
162
161
  # @return [Float] number of miles between geopoints.
163
162
  # @see #distance_in_km
164
- def distance_in_miles(geopoint,lng = nil)
163
+ def distance_in_miles(geopoint, lng = nil)
165
164
  distance_in_km(geopoint, lng) * 0.621371
166
165
  end
167
166
 
@@ -175,12 +174,12 @@ module Parse
175
174
  # @param lng [Float] Longitude assuming that the first parameter is a latitude instead of a GeoPoint.
176
175
  # @return [Float] number of miles between geopoints.
177
176
  # @see #distance_in_miles
178
- def distance_in_km(geopoint,lng = nil)
177
+ def distance_in_km(geopoint, lng = nil)
179
178
  unless geopoint.is_a?(Parse::GeoPoint)
180
179
  geopoint = Parse::GeoPoint.new(geopoint, lng)
181
180
  end
182
181
 
183
- dtor = Math::PI/180
182
+ dtor = Math::PI / 180
184
183
  r = 6378.14
185
184
  r_lat1 = self.latitude * dtor
186
185
  r_lng1 = self.longitude * dtor
@@ -190,13 +189,10 @@ module Parse
190
189
  delta_lat = r_lat1 - r_lat2
191
190
  delta_lng = r_lng1 - r_lng2
192
191
 
193
- a = (Math::sin(delta_lat/2.0) ** 2).to_f + (Math::cos(r_lat1) * Math::cos(r_lat2) * ( Math::sin(delta_lng/2.0) ** 2 ) )
194
- c = 2.0 * Math::atan2(Math::sqrt(a), Math::sqrt(1.0-a))
192
+ a = (Math::sin(delta_lat / 2.0) ** 2).to_f + (Math::cos(r_lat1) * Math::cos(r_lat2) * (Math::sin(delta_lng / 2.0) ** 2))
193
+ c = 2.0 * Math::atan2(Math::sqrt(a), Math::sqrt(1.0 - a))
195
194
  d = r * c
196
195
  d
197
196
  end
198
-
199
-
200
197
  end
201
-
202
198
  end
@@ -1,12 +1,12 @@
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 'active_model_serializers'
9
- require_relative '../client'
4
+ require "active_model"
5
+ require "active_support"
6
+ require "active_support/inflector"
7
+ require "active_support/core_ext/object"
8
+ require "active_model_serializers"
9
+ require_relative "../client"
10
10
 
11
11
  module Parse
12
12
  # Find a corresponding Parse::Object subclass for this string or symbol
@@ -21,61 +21,59 @@ module Parse
21
21
  # serialization, dirty tracking, callbacks, etc.
22
22
  # @see ActiveModel
23
23
  class Model
24
-
25
24
  include Client::Connectable # allows easy default Parse::Client access
26
25
  include ::ActiveModel::Model
27
26
  include ::ActiveModel::Serializers::JSON # support for JSON Serializers
28
27
  include ::ActiveModel::Dirty # adds dirty tracking support
29
28
  include ::ActiveModel::Conversion
30
- extend ::ActiveModel::Callbacks # callback support on save, update, delete, etc.
31
- extend ::ActiveModel::Naming # provides the methods for getting class names from Model classes
29
+ extend ::ActiveModel::Callbacks # callback support on save, update, delete, etc.
30
+ extend ::ActiveModel::Naming # provides the methods for getting class names from Model classes
32
31
 
33
32
  # The name of the field in a hash that contains information about the type
34
33
  # of data the hash represents.
35
- TYPE_FIELD = '__type'.freeze
34
+ TYPE_FIELD = "__type".freeze
36
35
 
37
36
  # The objectId field in Parse Objects.
38
- OBJECT_ID = 'objectId'.freeze
37
+ OBJECT_ID = "objectId".freeze
39
38
  # @see OBJECT_ID
40
39
  ID = "id".freeze
41
40
 
42
41
  # The key field for getting class information.
43
- KEY_CLASS_NAME = 'className'.freeze
42
+ KEY_CLASS_NAME = "className".freeze
44
43
  # @deprecated Use OBJECT_ID instead.
45
- KEY_OBJECT_ID = 'objectId'.freeze
44
+ KEY_OBJECT_ID = "objectId".freeze
46
45
  # The key field for getting the created at date of an object hash.
47
- KEY_CREATED_AT = 'createdAt'
46
+ KEY_CREATED_AT = "createdAt"
48
47
  # The key field for getting the updated at date of an object hash.
49
- KEY_UPDATED_AT = 'updatedAt'
48
+ KEY_UPDATED_AT = "updatedAt"
50
49
  # The collection for Users in Parse. Used by Parse::User.
51
- CLASS_USER = '_User'
50
+ CLASS_USER = "_User"
52
51
  # The collection for Installations in Parse. Used by Parse::Installation.
53
- CLASS_INSTALLATION = '_Installation'
52
+ CLASS_INSTALLATION = "_Installation"
54
53
  # The collection for revocable Sessions in Parse. Used by Parse::Session.
55
- CLASS_SESSION = '_Session'
54
+ CLASS_SESSION = "_Session"
56
55
  # The collection for Roles in Parse. Used by Parse::Role.
57
- CLASS_ROLE = '_Role'
56
+ CLASS_ROLE = "_Role"
58
57
  # The collection for to store Products (in-App purchases) in Parse. Used by Parse::Product.
59
- CLASS_PRODUCT = '_Product'
58
+ CLASS_PRODUCT = "_Product"
60
59
  # The type label for hashes containing file data. Used by Parse::File.
61
- TYPE_FILE = 'File'
60
+ TYPE_FILE = "File"
62
61
  # The type label for hashes containing geopoints. Used by Parse::GeoPoint.
63
- TYPE_GEOPOINT = 'GeoPoint'
62
+ TYPE_GEOPOINT = "GeoPoint"
64
63
  # The type label for hashes containing a Parse object. Used by Parse::Object and subclasses.
65
- TYPE_OBJECT = 'Object'
64
+ TYPE_OBJECT = "Object"
66
65
  # The type label for hashes containing a Parse date object. Used by Parse::Date.
67
- TYPE_DATE = 'Date'
66
+ TYPE_DATE = "Date"
68
67
  # The type label for hashes containing 'byte' data. Used by Parse::Bytes.
69
- TYPE_BYTES = 'Bytes'
68
+ TYPE_BYTES = "Bytes"
70
69
  # The type label for hashes containing ACL data. Used by Parse::ACL
71
- TYPE_ACL = 'ACL'
70
+ TYPE_ACL = "ACL"
72
71
  # The type label for hashes storing numeric data.
73
- TYPE_NUMBER = 'Number'
72
+ TYPE_NUMBER = "Number"
74
73
  # The type label for hashes containing a Parse pointer.
75
- TYPE_POINTER = 'Pointer'
74
+ TYPE_POINTER = "Pointer"
76
75
  # The type label for hashes representing relational data.
77
- TYPE_RELATION = 'Relation'
78
-
76
+ TYPE_RELATION = "Relation"
79
77
 
80
78
  # To support being able to have different ruby class names from the 'table'
81
79
  # names used in Parse, we will need to have a dynamic lookup system where
@@ -115,7 +113,6 @@ module Parse
115
113
  def raise_on_save_failure=(bool)
116
114
  @global_raise_on_save_failure = bool
117
115
  end
118
-
119
116
  end
120
117
 
121
118
  # Find a Parse::Model subclass matching this type or Pares collection name.
@@ -149,11 +146,8 @@ module Parse
149
146
  @@model_cache[str] ||= Parse::Object.descendants.find do |f|
150
147
  f.parse_class == str || f.parse_class == "_#{str}"
151
148
  end
152
-
153
149
  end
154
-
155
150
  end
156
-
157
151
  end
158
152
 
159
153
  # Add extensions to the String class.
@@ -172,9 +166,9 @@ class String
172
166
  # @return [String]
173
167
  # @see Parse::Query.field_formatter
174
168
  def columnize
175
- return Parse::Model::OBJECT_ID if self == Parse::Model::ID
176
- u = '_'.freeze
177
- (first == u ? sub(u,'') : self).camelize(:lower)
169
+ return Parse::Model::OBJECT_ID if self == Parse::Model::ID
170
+ u = "_".freeze
171
+ (first == u ? sub(u, "") : self).camelize(:lower)
178
172
  end
179
173
 
180
174
  # Convert a string to a Parse class name. This method tries to find a
@@ -1,42 +1,41 @@
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'
8
- require 'active_support/core_ext/object'
9
- require 'active_support/core_ext/string'
10
- require 'active_model_serializers'
11
- require 'time'
12
- require 'open-uri'
13
-
14
- require_relative '../client'
15
- require_relative 'model'
16
- require_relative 'pointer'
17
- require_relative 'geopoint'
18
- require_relative 'file'
19
- require_relative 'bytes'
20
- require_relative 'date'
21
- require_relative 'time_zone'
22
- require_relative 'acl'
23
- require_relative 'push'
24
- require_relative 'core/actions'
25
- require_relative 'core/fetching'
26
- require_relative 'core/querying'
27
- require_relative 'core/schema'
28
- require_relative 'core/properties'
29
- require_relative 'core/errors'
30
- require_relative 'core/builder'
31
- require_relative 'associations/has_one'
32
- require_relative 'associations/belongs_to'
33
- require_relative 'associations/has_many'
34
-
4
+ require "active_model"
5
+ require "active_support"
6
+ require "active_support/inflector"
7
+ require "active_support/core_ext"
8
+ require "active_support/core_ext/object"
9
+ require "active_support/core_ext/string"
10
+ require "active_model_serializers"
11
+ require "time"
12
+ require "open-uri"
13
+
14
+ require_relative "../client"
15
+ require_relative "model"
16
+ require_relative "pointer"
17
+ require_relative "geopoint"
18
+ require_relative "file"
19
+ require_relative "bytes"
20
+ require_relative "date"
21
+ require_relative "time_zone"
22
+ require_relative "acl"
23
+ require_relative "push"
24
+ require_relative "core/actions"
25
+ require_relative "core/fetching"
26
+ require_relative "core/querying"
27
+ require_relative "core/schema"
28
+ require_relative "core/properties"
29
+ require_relative "core/errors"
30
+ require_relative "core/builder"
31
+ require_relative "associations/has_one"
32
+ require_relative "associations/belongs_to"
33
+ require_relative "associations/has_many"
35
34
 
36
35
  module Parse
37
36
  # @return [Array] an array of registered Parse::Object subclasses.
38
37
  def self.registered_classes
39
- Parse::Object.descendants.map(&:parse_class).uniq
38
+ Parse::Object.descendants.map(&:parse_class).uniq
40
39
  end
41
40
 
42
41
  # @return [Array<Hash>] the list of all schemas for this application.
@@ -65,7 +64,7 @@ module Parse
65
64
  # Alias shorter names of core Parse class names.
66
65
  # Ex, alias Parse::User to User, Parse::Installation to Installation, etc.
67
66
  def self.use_shortnames!
68
- require_relative 'shortnames'
67
+ require_relative "shortnames"
69
68
  end
70
69
 
71
70
  # This is the core class for all app specific Parse table subclasses. This class
@@ -139,7 +138,7 @@ module Parse
139
138
  BASE_OBJECT_CLASS = "Parse::Object".freeze
140
139
 
141
140
  # @return [Model::TYPE_OBJECT]
142
- def __type; Parse::Model::TYPE_OBJECT; end;
141
+ def __type; Parse::Model::TYPE_OBJECT; end
143
142
 
144
143
  # Default ActiveModel::Callbacks
145
144
  # @!group Callbacks
@@ -183,7 +182,6 @@ module Parse
183
182
  # the remote Parse table is named 'Artist'. You may override this behavior by utilizing the `parse_class(<className>)` method
184
183
  # to set it to something different.
185
184
  class << self
186
-
187
185
  attr_accessor :parse_class
188
186
  attr_reader :default_acls
189
187
 
@@ -253,7 +251,6 @@ module Parse
253
251
  def acl(acls, owner: nil)
254
252
  raise "[#{self}.acl DEPRECATED] - Use `#{self}.default_acl` instead."
255
253
  end
256
-
257
254
  end # << self
258
255
 
259
256
  # @return [String] the Parse class for this object.
@@ -261,6 +258,7 @@ module Parse
261
258
  def parse_class
262
259
  self.class.parse_class
263
260
  end
261
+
264
262
  alias_method :className, :parse_class
265
263
 
266
264
  # @return [Hash] the schema structure for this Parse collection from the server.
@@ -347,7 +345,7 @@ module Parse
347
345
  # @param opts [Hash] a set of options to send to fetch!
348
346
  # @see Fetching#fetch!
349
347
  def reload!(opts = {})
350
- # get the values from the persistence layer
348
+ # get the values from the persistence layer
351
349
  fetch!(opts)
352
350
  clear_changes!
353
351
  end
@@ -436,7 +434,7 @@ module Parse
436
434
  # @return [String] a pretty-formatted JSON string
437
435
  # @see JSON.pretty_generate
438
436
  def pretty
439
- JSON.pretty_generate( as_json )
437
+ JSON.pretty_generate(as_json)
440
438
  end
441
439
 
442
440
  # clear all change and dirty tracking information.
@@ -483,10 +481,10 @@ module Parse
483
481
  o = Parse::Pointer.new className, (json[Parse::Model::OBJECT_ID] || json[:objectId])
484
482
  end
485
483
  return o
486
- # rescue NameError => e
487
- # puts "Parse::Object.build constant class error: #{e}"
488
- # rescue Exception => e
489
- # puts "Parse::Object.build error: #{e}"
484
+ # rescue NameError => e
485
+ # puts "Parse::Object.build constant class error: #{e}"
486
+ # rescue Exception => e
487
+ # puts "Parse::Object.build error: #{e}"
490
488
  end
491
489
 
492
490
  # @!attribute id
@@ -521,13 +519,11 @@ module Parse
521
519
  # @param key (see Parse::Object#[])
522
520
  # @param value [Object] the value to set this property.
523
521
  # @return [Object] the value passed in.
524
- def []=(key,value)
522
+ def []=(key, value)
525
523
  return unless self.class.fields[key.to_sym].present?
526
- send("#{key}=",value)
524
+ send("#{key}=", value)
527
525
  end
528
-
529
526
  end
530
-
531
527
  end
532
528
 
533
529
  class Hash
@@ -540,7 +536,6 @@ class Hash
540
536
  def parse_object
541
537
  Parse::Object.build(self)
542
538
  end
543
-
544
539
  end
545
540
 
546
541
  class Array
@@ -565,12 +560,11 @@ class Array
565
560
  def parse_ids
566
561
  parse_objects.map(&:id)
567
562
  end
568
-
569
563
  end
570
564
 
571
565
  # Load all the core classes.
572
- require_relative 'classes/installation'
573
- require_relative 'classes/product'
574
- require_relative 'classes/role'
575
- require_relative 'classes/session'
576
- require_relative 'classes/user'
566
+ require_relative "classes/installation"
567
+ require_relative "classes/product"
568
+ require_relative "classes/role"
569
+ require_relative "classes/session"
570
+ require_relative "classes/user"
@@ -1,199 +1,200 @@
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'
8
- require 'active_model_serializers'
9
- require_relative 'model'
4
+ require "active_model"
5
+ require "active_support"
6
+ require "active_support/inflector"
7
+ require "active_support/core_ext"
8
+ require "active_model_serializers"
9
+ require_relative "model"
10
+
10
11
  module Parse
11
12
 
12
- # The Pointer class represents the pointer type in Parse and is the superclass
13
- # of Parse::Object types. A pointer can be considered a type of Parse::Object
14
- # in which only the class name and id is known. In most cases, you may not
15
- # deal with Parse::Pointer objects directly if you have defined all your
16
- # Parse::Object subclasses.
17
- #
18
- # A `Parse::Pointer` only contains data about the specific Parse class and
19
- # the `id` for the object. Therefore, creating an instance of any
20
- # Parse::Object subclass with only the `:id` field set will be
21
- # considered in "pointer" state even though its specific class is not
22
- # `Parse::Pointer` type. The only case that you may have a Parse::Pointer
23
- # is in the case where an object was received for one of your classes and
24
- # the framework has no registered class handler for it.
25
- # Assume you have the tables `Post`, `Comment` and `Author` defined in your
26
- # remote Parse database, but have only defined `Post` and `Commentary`
27
- # locally.
28
- # @example
29
- # class Post < Parse::Object
30
- # end
31
- #
32
- # class Commentary < Parse::Object
33
- # belongs_to :post
34
- # belongs_to :author
35
- # end
36
- #
37
- # comment = Commentary.first
38
- # comment.post? # true because it is non-nil
39
- # comment.artist? # true because it is non-nil
40
- #
41
- # # both are true because they are in a Pointer state
42
- # comment.post.pointer? # true
43
- # comment.author.pointer? # true
44
- #
45
- # # we have defined a Post class handler
46
- # comment.post # <Post @parse_class="Post", @id="xdqcCqfngz">
47
- #
48
- # # we have not defined an Author class handler
49
- # comment.author # <Parse::Pointer @parse_class="Author", @id="hZLbW6ofKC">
50
- #
51
- #
52
- # comment.post.fetch # fetch the relation
53
- # comment.post.pointer? # false, it is now a full object.
54
- #
55
- # The effect is that for any unknown classes that the framework encounters,
56
- # it will generate Parse::Pointer instances until you define those classes
57
- # with valid properties and associations. While this might be ok for some
58
- # classes you do not use, we still recommend defining all your Parse classes
59
- # locally in the framework.
60
- #
61
- # Once you have a subclass, you may also create a Parse::Pointer object using
62
- # the _pointer_ method.
63
- # @example
64
- # Parse::User.pointer("123456") # => Parse::Pointer for "_User" class
65
- #
66
- # @see Parse::Object
67
- class Pointer < Model
68
- # The default attributes in a Parse Pointer hash.
69
- ATTRIBUTES = { __type: :string, className: :string, objectId: :string}.freeze
70
- # @return [String] the name of the Parse class for this pointer.
71
- attr_accessor :parse_class
72
- # @return [String] the objectId field
73
- attr_accessor :id
74
-
75
- # @return [Model::TYPE_POINTER]
76
- def __type; Parse::Model::TYPE_POINTER; end;
77
- alias_method :className, :parse_class
78
- # A Parse object as a className field and objectId. In ruby, we will use the
79
- # id attribute method, but for usability, we will also alias it to objectId
80
- alias_method :objectId, :id
81
-
82
- # A Parse pointer only requires the name of the remote Parse collection name,
83
- # and the `objectId` of the record.
84
- # @param table [String] The Parse class name in the Parse database.
85
- # @param oid [String] The objectId
86
- def initialize(table, oid)
87
- @parse_class = table.to_s
88
- @id = oid.to_s
89
- end
13
+ # The Pointer class represents the pointer type in Parse and is the superclass
14
+ # of Parse::Object types. A pointer can be considered a type of Parse::Object
15
+ # in which only the class name and id is known. In most cases, you may not
16
+ # deal with Parse::Pointer objects directly if you have defined all your
17
+ # Parse::Object subclasses.
18
+ #
19
+ # A `Parse::Pointer` only contains data about the specific Parse class and
20
+ # the `id` for the object. Therefore, creating an instance of any
21
+ # Parse::Object subclass with only the `:id` field set will be
22
+ # considered in "pointer" state even though its specific class is not
23
+ # `Parse::Pointer` type. The only case that you may have a Parse::Pointer
24
+ # is in the case where an object was received for one of your classes and
25
+ # the framework has no registered class handler for it.
26
+ # Assume you have the tables `Post`, `Comment` and `Author` defined in your
27
+ # remote Parse database, but have only defined `Post` and `Commentary`
28
+ # locally.
29
+ # @example
30
+ # class Post < Parse::Object
31
+ # end
32
+ #
33
+ # class Commentary < Parse::Object
34
+ # belongs_to :post
35
+ # belongs_to :author
36
+ # end
37
+ #
38
+ # comment = Commentary.first
39
+ # comment.post? # true because it is non-nil
40
+ # comment.artist? # true because it is non-nil
41
+ #
42
+ # # both are true because they are in a Pointer state
43
+ # comment.post.pointer? # true
44
+ # comment.author.pointer? # true
45
+ #
46
+ # # we have defined a Post class handler
47
+ # comment.post # <Post @parse_class="Post", @id="xdqcCqfngz">
48
+ #
49
+ # # we have not defined an Author class handler
50
+ # comment.author # <Parse::Pointer @parse_class="Author", @id="hZLbW6ofKC">
51
+ #
52
+ #
53
+ # comment.post.fetch # fetch the relation
54
+ # comment.post.pointer? # false, it is now a full object.
55
+ #
56
+ # The effect is that for any unknown classes that the framework encounters,
57
+ # it will generate Parse::Pointer instances until you define those classes
58
+ # with valid properties and associations. While this might be ok for some
59
+ # classes you do not use, we still recommend defining all your Parse classes
60
+ # locally in the framework.
61
+ #
62
+ # Once you have a subclass, you may also create a Parse::Pointer object using
63
+ # the _pointer_ method.
64
+ # @example
65
+ # Parse::User.pointer("123456") # => Parse::Pointer for "_User" class
66
+ #
67
+ # @see Parse::Object
68
+ class Pointer < Model
69
+ # The default attributes in a Parse Pointer hash.
70
+ ATTRIBUTES = { __type: :string, className: :string, objectId: :string }.freeze
71
+ # @return [String] the name of the Parse class for this pointer.
72
+ attr_accessor :parse_class
73
+ # @return [String] the objectId field
74
+ attr_accessor :id
75
+
76
+ # @return [Model::TYPE_POINTER]
77
+ def __type; Parse::Model::TYPE_POINTER; end
78
+
79
+ alias_method :className, :parse_class
80
+ # A Parse object as a className field and objectId. In ruby, we will use the
81
+ # id attribute method, but for usability, we will also alias it to objectId
82
+ alias_method :objectId, :id
83
+
84
+ # A Parse pointer only requires the name of the remote Parse collection name,
85
+ # and the `objectId` of the record.
86
+ # @param table [String] The Parse class name in the Parse database.
87
+ # @param oid [String] The objectId
88
+ def initialize(table, oid)
89
+ @parse_class = table.to_s
90
+ @id = oid.to_s
91
+ end
90
92
 
91
- # @return [String] the name of the collection for this Pointer.
92
- def parse_class
93
- @parse_class
94
- end
93
+ # @return [String] the name of the collection for this Pointer.
94
+ def parse_class
95
+ @parse_class
96
+ end
95
97
 
96
- # @return [String] a string representing the class and id of this instance.
97
- def sig
98
- "#{@parse_class}##{id || 'new'}"
99
- end
98
+ # @return [String] a string representing the class and id of this instance.
99
+ def sig
100
+ "#{@parse_class}##{id || "new"}"
101
+ end
100
102
 
101
- # @return [Hash]
102
- def attributes
103
- ATTRIBUTES
104
- end
103
+ # @return [Hash]
104
+ def attributes
105
+ ATTRIBUTES
106
+ end
105
107
 
106
- # @return [Hash] serialized JSON structure
107
- def json_hash
108
- JSON.parse to_json
109
- end
108
+ # @return [Hash] serialized JSON structure
109
+ def json_hash
110
+ JSON.parse to_json
111
+ end
110
112
 
111
- # Create a new pointer with the current class name and id. While this may not make sense
112
- # for a pointer instance, Parse::Object subclasses use this inherited method to turn themselves into
113
- # pointer objects.
114
- # @example
115
- # user = Parse::User.first
116
- # user.pointer # => Parse::Pointer("_User", user.id)
117
- #
118
- # @return [Pointer] a new Pointer for this object.
119
- # @see Parse::Object
120
- def pointer
121
- Pointer.new parse_class, @id
122
- end
113
+ # Create a new pointer with the current class name and id. While this may not make sense
114
+ # for a pointer instance, Parse::Object subclasses use this inherited method to turn themselves into
115
+ # pointer objects.
116
+ # @example
117
+ # user = Parse::User.first
118
+ # user.pointer # => Parse::Pointer("_User", user.id)
119
+ #
120
+ # @return [Pointer] a new Pointer for this object.
121
+ # @see Parse::Object
122
+ def pointer
123
+ Pointer.new parse_class, @id
124
+ end
123
125
 
124
- # Whether this instance is in pointer state. A pointer is determined
125
- # if we have a parse class and an id, but no created_at or updated_at fields.
126
- # @return [Boolean] true if instance is in pointer state.
127
- def pointer?
128
- present? && @created_at.blank? && @updated_at.blank?
129
- end
126
+ # Whether this instance is in pointer state. A pointer is determined
127
+ # if we have a parse class and an id, but no created_at or updated_at fields.
128
+ # @return [Boolean] true if instance is in pointer state.
129
+ def pointer?
130
+ present? && @created_at.blank? && @updated_at.blank?
131
+ end
130
132
 
131
- # Returns true if the data for this instance has been fetched. Because of some autofetching
132
- # mechanisms, this is useful to know whether the object already has data without actually causing
133
- # a fetch of the data.
134
- # @return [Boolean] true if not in pointer state.
135
- def fetched?
136
- present? && pointer? == false
137
- end
133
+ # Returns true if the data for this instance has been fetched. Because of some autofetching
134
+ # mechanisms, this is useful to know whether the object already has data without actually causing
135
+ # a fetch of the data.
136
+ # @return [Boolean] true if not in pointer state.
137
+ def fetched?
138
+ present? && pointer? == false
139
+ end
138
140
 
139
- # This method is a general implementation that gets overriden by Parse::Object subclass.
140
- # Given the class name and the id, we will go to Parse and fetch the actual record, returning the
141
- # JSON object.
142
- # @return [Parse::Object] the fetched Parse::Object, nil otherwise.
143
- def fetch
144
- response = client.fetch_object(parse_class, id)
145
- return nil if response.error?
146
- response.result
147
- end
141
+ # This method is a general implementation that gets overriden by Parse::Object subclass.
142
+ # Given the class name and the id, we will go to Parse and fetch the actual record, returning the
143
+ # JSON object.
144
+ # @return [Parse::Object] the fetched Parse::Object, nil otherwise.
145
+ def fetch
146
+ response = client.fetch_object(parse_class, id)
147
+ return nil if response.error?
148
+ response.result
149
+ end
148
150
 
149
- # Two Parse::Pointers (or Parse::Objects) are equal if both of them have
150
- # the same Parse class and the same id.
151
- # @return [Boolean]
152
- def ==(o)
153
- return false unless o.is_a?(Pointer)
154
- #only equal if the Parse class and object ID are the same.
155
- self.parse_class == o.parse_class && id == o.id
156
- end
157
- alias_method :eql?, :==
158
-
159
- # Compute a hash-code for this object. It is calculated
160
- # by combining the Parse class name, the {Parse::Object#id} field and
161
- # any pending changes.
162
- #
163
- # Two objects with the same content will have the same hash code
164
- # (and will compare using eql?).
165
- # @return [Fixnum]
166
- def hash
167
- "#{parse_class}#{id}#{changes.to_s}".hash
168
- end
151
+ # Two Parse::Pointers (or Parse::Objects) are equal if both of them have
152
+ # the same Parse class and the same id.
153
+ # @return [Boolean]
154
+ def ==(o)
155
+ return false unless o.is_a?(Pointer)
156
+ #only equal if the Parse class and object ID are the same.
157
+ self.parse_class == o.parse_class && id == o.id
158
+ end
169
159
 
170
- # @return [Boolean] true if instance has a Parse class and an id.
171
- def present?
172
- parse_class.present? && @id.present?
173
- end
160
+ alias_method :eql?, :==
174
161
 
175
- # Access the pointer properties through hash accessor. This is done for
176
- # compatibility with the hash access of a Parse::Object. This method
177
- # returns nil if the key is not one of: :id, :objectId, or :className.
178
- # @param key [String] the name of the property.
179
- # @return [Object] the value for this key.
180
- def [](key)
181
- return nil unless [:id,:objectId,:className].include?(key.to_sym)
182
- send(key)
183
- end
162
+ # Compute a hash-code for this object. It is calculated
163
+ # by combining the Parse class name, the {Parse::Object#id} field and
164
+ # any pending changes.
165
+ #
166
+ # Two objects with the same content will have the same hash code
167
+ # (and will compare using eql?).
168
+ # @return [Fixnum]
169
+ def hash
170
+ "#{parse_class}#{id}#{changes.to_s}".hash
171
+ end
184
172
 
185
- # Set the pointer properties through hash accessor. This is done for
186
- # compatibility with the hash access of a Parse::Object. This method
187
- # does nothing if the key is not one of: :id, :objectId, or :className.
188
- # @param key (see #[])
189
- # @return [Object]
190
- def []=(key,value)
191
- return unless [:id,:objectId,:className].include?(key.to_sym)
192
- send("#{key}=",value)
193
- end
173
+ # @return [Boolean] true if instance has a Parse class and an id.
174
+ def present?
175
+ parse_class.present? && @id.present?
176
+ end
194
177
 
178
+ # Access the pointer properties through hash accessor. This is done for
179
+ # compatibility with the hash access of a Parse::Object. This method
180
+ # returns nil if the key is not one of: :id, :objectId, or :className.
181
+ # @param key [String] the name of the property.
182
+ # @return [Object] the value for this key.
183
+ def [](key)
184
+ return nil unless [:id, :objectId, :className].include?(key.to_sym)
185
+ send(key)
195
186
  end
196
187
 
188
+ # Set the pointer properties through hash accessor. This is done for
189
+ # compatibility with the hash access of a Parse::Object. This method
190
+ # does nothing if the key is not one of: :id, :objectId, or :className.
191
+ # @param key (see #[])
192
+ # @return [Object]
193
+ def []=(key, value)
194
+ return unless [:id, :objectId, :className].include?(key.to_sym)
195
+ send("#{key}=", value)
196
+ end
197
+ end
197
198
  end
198
199
 
199
200
  # extensions