module Graphiti::Resource::Polymorphism::ClassMethods
Public Instance Methods
Source
# File lib/graphiti/resource/polymorphism.rb, line 59 def children @children ||= polymorphic.map { |klass| klass.is_a?(String) ? klass.safe_constantize : klass } end
Source
# File lib/graphiti/resource/polymorphism.rb, line 36 def inherited(klass) klass.type = nil klass.model = klass.infer_model klass.endpoint = klass.infer_endpoint klass.polymorphic_child = true super end
Calls superclass method
Source
# File lib/graphiti/resource/polymorphism.rb, line 74 def resource_for_model(model) resource = children.find { |c| model.instance_of?(c.model) } || children.find { |c| model.is_a?(c.model) } if resource.nil? raise Errors::PolymorphicResourceChildNotFound.new(self, model: model) else resource end end
Source
# File lib/graphiti/resource/polymorphism.rb, line 65 def resource_for_type(type) resource = children.find { |c| c.type.to_s == type.to_s } if resource.nil? raise Errors::PolymorphicResourceChildNotFound.new(self, type: type) else resource end end
Source
# File lib/graphiti/resource/polymorphism.rb, line 44 def sideload(name) if (split_on = name.to_s.split(/^on__/)).length > 1 on_type, name = split_on[1].split("--").map(&:to_sym) end sl = super(name) if !polymorphic_child? && sl.nil? children.each do |c| next if on_type && c.type != on_type break if (sl = c.sideloads[name]) end end sl end
Calls superclass method