class Syncify::Association::PolymorphicAssociation
Attributes
destination[RW]
from_class[RW]
name[RW]
to_classes[RW]
traversed[RW]
Public Class Methods
identify_to_classes(from_class, association_name)
click to toggle source
# File lib/syncify/association/polymorphic_association.rb, line 6 def self.identify_to_classes(from_class, association_name) association = from_class.reflect_on_association(association_name) @cache ||= {} @cache[from_class] ||= {} @cache[from_class][association_name] ||= from_class. where("#{association.foreign_type} != ''"). distinct. pluck(association.foreign_type). uniq. compact. map(&:constantize) end
new(from_class:, association:, destination:)
click to toggle source
# File lib/syncify/association/polymorphic_association.rb, line 19 def initialize(from_class:, association:, destination:) @from_class = from_class @to_classes = Syncify::Association::PolymorphicAssociation.identify_to_classes(from_class, association.name) @name = association.name @destination = destination @traversed = false end
Public Instance Methods
create_destination(association_name)
click to toggle source
# File lib/syncify/association/polymorphic_association.rb, line 45 def create_destination(association_name) destination[name] ||= {} destination[name][association_name] = {} end
eql?(other_association)
click to toggle source
# File lib/syncify/association/polymorphic_association.rb, line 54 def eql?(other_association) return false unless other_association.is_a? PolymorphicAssociation self.from_class == other_association.from_class && self.to_classes == other_association.to_classes && self.name == other_association.name end
hash()
click to toggle source
# File lib/syncify/association/polymorphic_association.rb, line 50 def hash "#{self.from_class.to_s}#{self.to_classes.map(&:to_s)}#{self.name}".hash end
inverse_of?(association)
click to toggle source
# File lib/syncify/association/polymorphic_association.rb, line 35 def inverse_of?(association) if association.polymorphic? association.to_classes.include?(from_class) && to_classes.include?(association.from_class) else from_class == association.to_class && to_classes.include?(association.from_class) end end
polymorphic?()
click to toggle source
# File lib/syncify/association/polymorphic_association.rb, line 27 def polymorphic? true end
traversed?()
click to toggle source
# File lib/syncify/association/polymorphic_association.rb, line 31 def traversed? traversed end