Sha256: 07e240e411006cfd62b8de738f577cf9576a5afaf4d4b6a4d0e2ff6439961203

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

module ActiveRecord
  class Base
    def is_mentionable?
      false
    end
  end
end

module Socialization
  module Mentionable
    extend ActiveSupport::Concern

    included do
      # Specifies if self can be mentioned.
      #
      # @return [Boolean]
      def is_mentionable?
        true
      end

      # Specifies if self is mentioned by a {Mentioner} object.
      #
      # @return [Boolean]
      def mentioned_by?(mentioner)
        raise ArgumentError, "#{mentioner} is not mentioner!"  unless mentioner.respond_to?(:is_mentioner?) && mentioner.is_mentioner?
        Socialization.mention_model.mentions?(mentioner, self)
      end

      # Returns an array of {Mentioner}s mentioning self.
      #
      # @param [Class] klass the {Mentioner} class to be included. e.g. `User`
      # @return [Array<Mentioner, Numeric>] An array of Mentioner objects or IDs
      def mentioners(klass, opts = {})
        Socialization.mention_model.mentioners(self, klass, opts)
      end

      # Returns a scope of the {Mentioner}s mentioning self.
      #
      # @param [Class] klass the {Mentioner} class to be included in the scope. e.g. `User`
      # @return ActiveRecord::Relation
      def mentioners_relation(klass, opts = {})
        Socialization.mention_model.mentioners_relation(self, klass, opts)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
socialization-0.5.0.beta2 lib/socialization/victims/mentionable.rb