Class: Parse::Pointer

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/datatypes.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Pointer

Returns a new instance of Pointer.



21
22
23
24
# File 'lib/parse/datatypes.rb', line 21

def initialize(data)
  @class_name       = data[Protocol::KEY_CLASS_NAME]
  @parse_object_id  = data[Protocol::KEY_OBJECT_ID]
end

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



11
12
13
# File 'lib/parse/datatypes.rb', line 11

def class_name
  @class_name
end

#parse_object_idObject Also known as: id

Returns the value of attribute parse_object_id.



10
11
12
# File 'lib/parse/datatypes.rb', line 10

def parse_object_id
  @parse_object_id
end

Class Method Details

.make(class_name, object_id) ⇒ Object



14
15
16
17
18
19
# File 'lib/parse/datatypes.rb', line 14

def self.make(class_name, object_id)
  Pointer.new(
    Protocol::KEY_CLASS_NAME => class_name,
    Protocol::KEY_OBJECT_ID => object_id
  )
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


32
33
34
# File 'lib/parse/datatypes.rb', line 32

def eql?(other)
  Parse.object_pointer_equality?(self, other)
end

#get(client = nil) ⇒ Object

Retrieve the Parse object referenced by this pointer.



59
60
61
# File 'lib/parse/datatypes.rb', line 59

def get(client = nil)
  Parse.get(@class_name, @parse_object_id, client) if @parse_object_id
end

#hashObject



37
38
39
# File 'lib/parse/datatypes.rb', line 37

def hash
  Parse.object_pointer_hash(self)
end

#new?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/parse/datatypes.rb', line 41

def new?
  false
end

#pointerObject

make it easier to deal with the ambiguity of whether you’re passed a pointer or object



28
29
30
# File 'lib/parse/datatypes.rb', line 28

def pointer
  self
end

#to_h(*_a) ⇒ Object Also known as: as_json



45
46
47
48
49
50
51
# File 'lib/parse/datatypes.rb', line 45

def to_h(*_a)
  {
    Protocol::KEY_TYPE        => Protocol::TYPE_POINTER,
    Protocol::KEY_CLASS_NAME  => @class_name,
    Protocol::KEY_OBJECT_ID   => @parse_object_id
  }
end

#to_json(*a) ⇒ Object



54
55
56
# File 'lib/parse/datatypes.rb', line 54

def to_json(*a)
  to_h.to_json(*a)
end

#to_sObject



63
64
65
# File 'lib/parse/datatypes.rb', line 63

def to_s
  "#{@class_name}:#{@parse_object_id}"
end