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
# File 'lib/parse/pointer.rb', line 6

def initialize hash, parent=nil
  @raw_hash = hash
  @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

Instance Method Details

#loadObject



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

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

#to_hObject



19
20
21
22
23
24
25
# File 'lib/parse/pointer.rb', line 19

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

#to_json(*args) ⇒ Object



27
28
29
# File 'lib/parse/pointer.rb', line 27

def to_json *args
  to_h.to_json
end