8aa99e34b4
Instead of delegating. With a polymorphic relationship, relying on a certain attribute implies doing things like aliasing "mentioner" to "creator" or similar.
21 lines
468 B
Ruby
21 lines
468 B
Ruby
module User::Mentionable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
has_many :mentions, dependent: :destroy, inverse_of: :mentionee
|
|
end
|
|
|
|
def mentioned_by(mentioner, at:)
|
|
mentions.create! container: at, mentioner: mentioner
|
|
end
|
|
|
|
def mentionable_handles
|
|
[ initials, first_name, first_name_with_last_name_initial ].collect(&:downcase)
|
|
end
|
|
|
|
private
|
|
def first_name_with_last_name_initial
|
|
"#{first_name}#{last_name&.first}"
|
|
end
|
|
end
|