class ActsAsMentionable::RetrievePolymorphic
Attributes
polymorphic_association_name[R]
relation[R]
Public Class Methods
new(relation, polymorphic_association_name)
click to toggle source
# File lib/acts_as_mentionable/retrieve_polymorphic.rb, line 5 def initialize relation, polymorphic_association_name @relation = relation @polymorphic_association_name = polymorphic_association_name end
Public Instance Methods
call()
click to toggle source
# File lib/acts_as_mentionable/retrieve_polymorphic.rb, line 10 def call type_to_ids.map { |type, ids| type.constantize.unscoped.find ids }.flatten end
Private Instance Methods
type_and_id_list()
click to toggle source
# File lib/acts_as_mentionable/retrieve_polymorphic.rb, line 16 def type_and_id_list relation.pluck "#{polymorphic_association_name}_type", "#{polymorphic_association_name}_id" end
type_to_ids()
click to toggle source
# File lib/acts_as_mentionable/retrieve_polymorphic.rb, line 20 def type_to_ids type_and_id_list.group_by(&:first).each_with_object({}) do |(type, type_and_id), hash| hash[type] = type_and_id.map(&:last) end end