Sha256: 34a0e14253137c9ab1b247eea3350ccfe826e6359953d84acd25641d1b40d998

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

require "mongoid_forums/engine"
require 'mongoid_forums/sanitizer'
require 'sanitize'

module MongoidForums
  mattr_accessor :per_page, :user_class, :formatter, :email_from_address

  class << self
    def per_page
      @@per_page || 20
    end

    def decorate_user_class!
      MongoidForums.user_class.class_eval do

        has_many :mongoid_forums_posts, :class_name => "MongoidForums::Post", :foreign_key => "user_id"
        has_many :mongoid_forums_topics, :class_name => "MongoidForums::Topic", :foreign_key => "user_id"

        # Using +to_s+ by default for backwards compatibility
        def forum_display_name
          to_s
        end unless method_defined? :forum_display_name

      end
    end

    def user_class
      if @@user_class.is_a?(Class)
        raise "You can't set MongoidForums.user_class to be a class. Please use a string instead.\n\n " +
              "See https://github.com/radar/mongoid_forums/issues/88 for more information."
      elsif @@user_class.is_a?(String)
        begin
          Object.const_get(@@user_class)
        rescue NameError
          @@user_class.constantize
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongoid-forums-0.0.3 lib/mongoid_forums.rb
mongoid-forums-0.0.2 lib/mongoid_forums.rb
mongoid-forums-0.0.1 lib/mongoid_forums.rb