Module: Graphiti::Resource::Polymorphism

Defined in:
lib/graphiti/resource/polymorphism.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(klass) ⇒ Object



6
7
8
# File 'lib/graphiti/resource/polymorphism.rb', line 6

def self.prepended(klass)
  klass.extend ClassMethods
end

Instance Method Details

#_associate(meth, parent, other, association_name, type) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/graphiti/resource/polymorphism.rb', line 27

def _associate(meth, parent, other, association_name, type)
  child_resource = self.class.resource_for_model(parent)
  if child_resource.sideloads[association_name]
    child_resource.new.adapter
      .send(meth, parent, other, association_name, type)
  end
end

#associate(*args) ⇒ Object



23
24
25
# File 'lib/graphiti/resource/polymorphism.rb', line 23

def associate(*args)
  _associate(:associate, *args)
end

#associate_all(*args) ⇒ Object



19
20
21
# File 'lib/graphiti/resource/polymorphism.rb', line 19

def associate_all(*args)
  _associate(:associate_all, *args)
end

#serializer_for(model) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/graphiti/resource/polymorphism.rb', line 10

def serializer_for(model)
  if polymorphic_child?
    serializer
  else
    child = self.class.resource_for_model(model)
    child.serializer
  end
end