Class: Parse::Role::RoleItemArray

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

Instance Attribute Summary

Attributes inherited from Array

#query_count

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ RoleItemArray

Returns a new instance of RoleItemArray.



20
21
22
# File 'lib/parse/role.rb', line 20

def initialize klass
  @klass = klass
end

Instance Method Details

#add(item) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/parse/role.rb', line 24

def add item
  push \
    case item
    when String, Symbol
      @klass.new('objectId' => item).pointer
    when @klass
      item.pointer
    when Pointer
      super
    else
      raise ArgumentError.new("wrong type: #{item.class.name}")
    end
end

#to_hObject



38
39
40
41
42
43
# File 'lib/parse/role.rb', line 38

def to_h
  {
    "__op" => "AddRelation",
    "objects" => map {|r| JSON.parse(r.to_json)}
  }
end

#to_json(*args) ⇒ Object



45
46
47
# File 'lib/parse/role.rb', line 45

def to_json *args
  to_h.to_json
end