Class: Parse::Pointer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, parent = nil) ⇒ Pointer

Returns a new instance of Pointer.



6
7
8
9
10
11
12
13
14
# File 'lib/parse/pointer.rb', line 6

def initialize hash, parent=nil
  @raw_hash = hash
  @parse_object_id = hash['objectId']
  @parent_object = parent

  if @raw_hash.has_key? 'body'
    @object = pointed_parse_class.new @raw_hash['body']
  end
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



4
5
6
# File 'lib/parse/pointer.rb', line 4

def object
  @object
end

#parse_object_idObject (readonly)

Returns the value of attribute parse_object_id.



4
5
6
# File 'lib/parse/pointer.rb', line 4

def parse_object_id
  @parse_object_id
end

Instance Method Details

#loadObject



16
17
18
# File 'lib/parse/pointer.rb', line 16

def load
  @object ||= pointed_parse_class.find_by_id @raw_hash['objectId']
end

#load!Object

TODO: should be refactored



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

def load!
  @object ||= pointed_parse_class.find_by_id! @raw_hash['objectId']
end

#to_hObject



25
26
27
28
29
30
31
# File 'lib/parse/pointer.rb', line 25

def to_h
  {
    "__type" => "Pointer",
    "className" => "#{@raw_hash['className']}",
    "objectId" => "#{@raw_hash['objectId']}"
  }
end

#to_json(*args) ⇒ Object



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

def to_json *args
  to_h.to_json
end