Method: JSONAPI::Relationship.polymorphic_types

Defined in:
lib/jsonapi/relationship.rb

.polymorphic_types(name) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/jsonapi/relationship.rb', line 69

def self.polymorphic_types(name)
  @poly_hash ||= {}.tap do |hash|
    ObjectSpace.each_object do |klass|
      next unless Module === klass
      if ActiveRecord::Base > klass
        klass.reflect_on_all_associations(:has_many).select{|r| r.options[:as] }.each do |reflection|
          (hash[reflection.options[:as]] ||= []) << klass.name.underscore
        end
      end
    end
  end
  @poly_hash[name.to_sym]
end