Sha256: 1af7e44c7d798f6b64c052c5c0df3bcbd6a6dfd80a84c9f8eacdd5cd0ffa0416
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
module ActiveRecord class Base def is_mentionable? false end end end module Socialization module Mentionable extend ActiveSupport::Concern included do # A mentioning is the Mention record of describing the mention relationship between # the mentionner and the mentionable (self). has_many :mentionings, :as => :mentionable, :dependent => :destroy, :class_name => 'Mention' def is_mentionable? true end def mentioned_by?(mentionner) raise ArgumentError, "#{mentionner} is not a mentionner!" unless mentionner.is_mentionner? !self.mentionings.where(:mentionner_type => mentionner.class.to_s, :mentionner_id => mentionner.id).empty? end def mentionners(klass) klass = klass.to_s.singularize.camelize.constantize unless klass.is_a?(Class) klass.joins("INNER JOIN mentions ON mentions.mentionner_id = #{klass.to_s.tableize}.id AND mentions.mentionner_type = '#{klass.to_s}'"). where("mentions.mentionable_type = '#{self.class.to_s}'"). where("mentions.mentionable_id = #{self.id}") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
socialization-0.3.0 | lib/socialization/mentionable.rb |