module Traits::Attribute::Polymorphism

Public Instance Methods

polymorphic_key?() click to toggle source
# File lib/traits/attribute/polymorphism.rb, line 7
def polymorphic_key?
  model.associations
    .first_where(
      polymorphic?:  true,
      from_key_name: name
    ).present?
end
polymorphic_type?() click to toggle source
# File lib/traits/attribute/polymorphism.rb, line 15
def polymorphic_type?
  model.associations
    .first_where(
      polymorphic?:                        true,
      attribute_name_for_polymorphic_type: name
    ).present?
end
to_hash() click to toggle source
Calls superclass method
# File lib/traits/attribute/polymorphism.rb, line 23
def to_hash
  super.merge!(
    polymorphic_key:  polymorphic_key?,
    polymorphic_type: polymorphic_type?
  )
end