Class: Parse::Pointer

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

Overview

Pointer


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Pointer

Returns a new instance of Pointer.



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

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.



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

def class_name
  @class_name
end

#parse_object_idObject Also known as: id

Returns the value of attribute parse_object_id.



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

def parse_object_id
  @parse_object_id
end

Instance Method Details

#as_json(*a) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/parse/datatypes.rb', line 35

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

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

Returns:

  • (Boolean)


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

def eql?(other)
  self.class.equal?(other.class) &&
    class_name == other.class_name &&
    parse_object_id == other.parse_object_id
end

#getObject

Retrieve the Parse object referenced by this pointer.



48
49
50
# File 'lib/parse/datatypes.rb', line 48

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

#hashObject



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

def hash
  class_name.hash ^ parse_object_id.hash
end

#pointerObject

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



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

def pointer
  self
end

#to_json(*a) ⇒ Object



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

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

#to_sObject



52
53
54
# File 'lib/parse/datatypes.rb', line 52

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