Class: Parse::Pointer
Overview
The Pointer class represents the pointer type in Parse and is the superclass of Parse::Object types. A pointer can be considered a type of Parse::Object in which only the class name and id is known. In most cases, you may not deal with Parse::Pointer objects directly if you have defined all your Parse::Object subclasses.
A `Parse::Pointer` only contains data about the specific Parse class and the `id` for the object. Therefore, creating an instance of any Parse::Object subclass with only the `:id` field set will be considered in “pointer” state even though its specific class is not `Parse::Pointer` type. The only case that you may have a Parse::Pointer is in the case where an object was received for one of your classes and the framework has no registered class handler for it. Assume you have the tables `Post`, `Comment` and `Author` defined in your remote Parse database, but have only defined `Post` and `Commentary` locally. The effect is that for any unknown classes that the framework encounters, it will generate Parse::Pointer instances until you define those classes with valid properties and associations. While this might be ok for some classes you do not use, we still recommend defining all your Parse classes locally in the framework.
Once you have a subclass, you may also create a Parse::Pointer object using the pointer method.
Direct Known Subclasses
Constant Summary collapse
- ATTRIBUTES =
The default attributes in a Parse Pointer hash.
{ __type: :string, className: :string, objectId: :string }.freeze
Constants inherited from Model
Model::CLASS_INSTALLATION, Model::CLASS_PRODUCT, Model::CLASS_ROLE, Model::CLASS_SESSION, Model::CLASS_USER, Model::ID, Model::KEY_CLASS_NAME, Model::KEY_CREATED_AT, Model::KEY_OBJECT_ID, Model::KEY_UPDATED_AT, Model::OBJECT_ID, Model::TYPE_ACL, Model::TYPE_BYTES, Model::TYPE_DATE, Model::TYPE_FIELD, Model::TYPE_FILE, Model::TYPE_GEOPOINT, Model::TYPE_NUMBER, Model::TYPE_OBJECT, Model::TYPE_POINTER, Model::TYPE_RELATION
Instance Attribute Summary collapse
- #id ⇒ String (also: #objectId)
The objectId field.
- #parse_class ⇒ String
The name of the collection for this Pointer.
Instance Method Summary collapse
- #==(o) ⇒ Boolean (also: #eql?)
Two Parse::Pointers (or Parse::Objects) are equal if both of them have the same Parse class and the same id.
- #[](key) ⇒ Object
Access the pointer properties through hash accessor.
- #[]=(key, value) ⇒ Object
Set the pointer properties through hash accessor.
- #__type ⇒ Model::TYPE_POINTER
- #attributes ⇒ Hash
- #className ⇒ String
The name of the Parse class for this pointer.
- #fetch ⇒ Parse::Object
This method is a general implementation that gets overriden by Parse::Object subclass.
- #fetched? ⇒ Boolean
Returns true if the data for this instance has been fetched.
- #hash ⇒ Fixnum
Compute a hash-code for this object.
- #initialize(table, oid) ⇒ Pointer constructor
A Parse pointer only requires the name of the remote Parse collection name, and the `objectId` of the record.
- #json_hash ⇒ Hash
Serialized JSON structure.
- #pointer ⇒ Pointer
Create a new pointer with the current class name and id.
- #pointer? ⇒ Boolean
Whether this instance is in pointer state.
- #present? ⇒ Boolean
True if instance has a Parse class and an id.
- #sig ⇒ String
A string representing the class and id of this instance.
Methods inherited from Model
Methods included from Client::Connectable
Constructor Details
#initialize(table, oid) ⇒ Pointer
A Parse pointer only requires the name of the remote Parse collection name, and the `objectId` of the record.
88 89 90 91 | # File 'lib/parse/model/pointer.rb', line 88 def initialize(table, oid) @parse_class = table.to_s @id = oid.to_s end |
Instance Attribute Details
#id ⇒ String Also known as: objectId
Returns the objectId field.
74 75 76 | # File 'lib/parse/model/pointer.rb', line 74 def id @id end |
#parse_class ⇒ String
Returns the name of the collection for this Pointer.
72 73 74 | # File 'lib/parse/model/pointer.rb', line 72 def parse_class @parse_class end |
Instance Method Details
#==(o) ⇒ Boolean Also known as: eql?
Two Parse::Pointers (or Parse::Objects) are equal if both of them have the same Parse class and the same id.
154 155 156 157 158 | # File 'lib/parse/model/pointer.rb', line 154 def ==(o) return false unless o.is_a?(Pointer) #only equal if the Parse class and object ID are the same. self.parse_class == o.parse_class && id == o.id end |
#[](key) ⇒ Object
Access the pointer properties through hash accessor. This is done for compatibility with the hash access of a Parse::Object. This method returns nil if the key is not one of: :id, :objectId, or :className.
183 184 185 186 | # File 'lib/parse/model/pointer.rb', line 183 def [](key) return nil unless [:id, :objectId, :className].include?(key.to_sym) send(key) end |
#[]=(key, value) ⇒ Object
Set the pointer properties through hash accessor. This is done for compatibility with the hash access of a Parse::Object. This method does nothing if the key is not one of: :id, :objectId, or :className.
193 194 195 196 | # File 'lib/parse/model/pointer.rb', line 193 def []=(key, value) return unless [:id, :objectId, :className].include?(key.to_sym) send("#{key}=", value) end |
#__type ⇒ Model::TYPE_POINTER
77 | # File 'lib/parse/model/pointer.rb', line 77 def __type; Parse::Model::TYPE_POINTER; end |
#attributes ⇒ Hash
104 105 106 | # File 'lib/parse/model/pointer.rb', line 104 def attributes ATTRIBUTES end |
#className ⇒ String
Returns the name of the Parse class for this pointer.
79 80 81 | # File 'lib/parse/model/pointer.rb', line 79 def parse_class @parse_class end |
#fetch ⇒ Parse::Object
This method is a general implementation that gets overriden by Parse::Object subclass. Given the class name and the id, we will go to Parse and fetch the actual record, returning the JSON object.
145 146 147 148 149 | # File 'lib/parse/model/pointer.rb', line 145 def fetch response = client.fetch_object(parse_class, id) return nil if response.error? response.result end |
#fetched? ⇒ Boolean
Returns true if the data for this instance has been fetched. Because of some autofetching mechanisms, this is useful to know whether the object already has data without actually causing a fetch of the data.
137 138 139 | # File 'lib/parse/model/pointer.rb', line 137 def fetched? present? && pointer? == false end |
#hash ⇒ Fixnum
Compute a hash-code for this object. It is calculated by combining the Parse class name, the Object#id field and any pending changes.
Two objects with the same content will have the same hash code (and will compare using eql?).
169 170 171 | # File 'lib/parse/model/pointer.rb', line 169 def hash "#{parse_class}#{id}#{changes.to_s}".hash end |
#json_hash ⇒ Hash
Returns serialized JSON structure.
109 110 111 | # File 'lib/parse/model/pointer.rb', line 109 def json_hash JSON.parse to_json end |
#pointer ⇒ Pointer
Create a new pointer with the current class name and id. While this may not make sense for a pointer instance, Parse::Object subclasses use this inherited method to turn themselves into pointer objects.
122 123 124 | # File 'lib/parse/model/pointer.rb', line 122 def pointer Pointer.new parse_class, @id end |
#pointer? ⇒ Boolean
Whether this instance is in pointer state. A pointer is determined if we have a parse class and an id, but no created_at or updated_at fields.
129 130 131 | # File 'lib/parse/model/pointer.rb', line 129 def pointer? present? && @created_at.blank? && @updated_at.blank? end |
#present? ⇒ Boolean
Returns true if instance has a Parse class and an id.
174 175 176 | # File 'lib/parse/model/pointer.rb', line 174 def present? parse_class.present? && @id.present? end |
#sig ⇒ String
Returns a string representing the class and id of this instance.
99 100 101 | # File 'lib/parse/model/pointer.rb', line 99 def sig "#{@parse_class}##{id || "new"}" end |