Class: Parse::Pointer

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

Overview

Pointer


Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Pointer


23
24
25
26
# File 'lib/parse/datatypes.rb', line 23

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


13
14
15
# File 'lib/parse/datatypes.rb', line 13

def class_name
  @class_name
end

#parse_object_idObject Also known as: id

Returns the value of attribute parse_object_id


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

def parse_object_id
  @parse_object_id
end

Class Method Details

.make(class_name, object_id) ⇒ Object


16
17
18
19
20
21
# File 'lib/parse/datatypes.rb', line 16

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: ==


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

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

#getObject

Retrieve the Parse object referenced by this pointer.


61
62
63
# File 'lib/parse/datatypes.rb', line 61

def get
  Parse.get @class_name, @parse_object_id if @parse_object_id
end

#hashObject


39
40
41
# File 'lib/parse/datatypes.rb', line 39

def hash
  Parse.object_pointer_hash(self)
end

#new?Boolean


43
44
45
# File 'lib/parse/datatypes.rb', line 43

def new?
  false
end

#pointerObject

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


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

def pointer
  self
end

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


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

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


56
57
58
# File 'lib/parse/datatypes.rb', line 56

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

#to_sObject


65
66
67
# File 'lib/parse/datatypes.rb', line 65

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