module Socialization::Mentioner
Public Instance Methods
Specifies if self can mention {Mentionable} objects.
@return [Boolean]
# File lib/socialization/actors/mentioner.rb, line 20 def is_mentioner? true end
Create a new {Mention mention} relationship.
@param [Mentionable] mentionable the object to be mentioned. @return [Boolean]
# File lib/socialization/actors/mentioner.rb, line 29 def mention!(mentionable) raise Socialization::ArgumentError, "#{mentionable} is not mentionable!" unless mentionable.respond_to?(:is_mentionable?) && mentionable.is_mentionable? Socialization.mention_model.mention!(self, mentionable) end
Returns all the mentionables of a certain type that are mentioned by self
@params [Mentionable] klass the type of {Mentionable} you want @params [Hash] opts a hash of options @return [Array<Mentionable, Numeric>] An array of Mentionable
objects or IDs
# File lib/socialization/actors/mentioner.rb, line 72 def mentionables(klass, opts = {}) Socialization.mention_model.mentionables(self, klass, opts) end
Returns a relation for all the mentionables of a certain type that are mentioned by self
@params [Mentionable] klass the type of {Mentionable} you want @params [Hash] opts a hash of options @return ActiveRecord::Relation
# File lib/socialization/actors/mentioner.rb, line 82 def mentionables_relation(klass, opts = {}) Socialization.mention_model.mentionables_relation(self, klass, opts) end
Specifies if self mentions a {Mentionable} object.
@param [Mentionable] mentionable the {Mentionable} object to test against. @return [Boolean]
# File lib/socialization/actors/mentioner.rb, line 62 def mentions?(mentionable) raise Socialization::ArgumentError, "#{mentionable} is not mentionable!" unless mentionable.respond_to?(:is_mentionable?) && mentionable.is_mentionable? Socialization.mention_model.mentions?(self, mentionable) end
Toggles a {Mention mention} relationship.
@param [Mentionable] mentionable the object to mention/unmention. @return [Boolean]
# File lib/socialization/actors/mentioner.rb, line 47 def toggle_mention!(mentionable) raise Socialization::ArgumentError, "#{mentionable} is not mentionable!" unless mentionable.respond_to?(:is_mentionable?) && mentionable.is_mentionable? if mentions?(mentionable) unmention!(mentionable) false else mention!(mentionable) true end end
Delete a {Mention mention} relationship.
@param [Mentionable] mentionable the object to unmention. @return [Boolean]
# File lib/socialization/actors/mentioner.rb, line 38 def unmention!(mentionable) raise Socialization::ArgumentError, "#{mentionable} is not mentionable!" unless mentionable.respond_to?(:is_mentionable?) && mentionable.is_mentionable? Socialization.mention_model.unmention!(self, mentionable) end