module GovernorComments::Comment

Public Class Methods

included(base) click to toggle source
# File lib/governor_comments/comment.rb, line 4
def self.included(base)
  base.belongs_to :commenter, :polymorphic => true
  if defined?(Rakismet)
    base.send :include, Rakismet::Model
    base.rakismet_attrs :author => proc { commenter.name },
                        :author_email => proc { commenter.email },
                        :author_url => proc { commenter.website },
                        :comment_type => 'comment'
  end
  
  base.scope :hidden, base.where(:hidden => true)
  base.scope :public, base.where(:hidden => false)
  
  base.validates_presence_of :content
  base.validates_presence_of :commenter
  base.validates_associated :commenter
end

Public Instance Methods

gravatar_url(size = 48, default = "http://github.com/images/gravatars/gravatar- click to toggle source
# File lib/governor_comments/comment.rb, line 32
def gravatar_url(size = 48, default = "http://github.com/images/gravatars/gravatar-#{size}.png")
  if commenter.respond_to? :email
    hash = Digest::MD5.hexdigest commenter.email.downcase
    "http://www.gravatar.com/avatar/#{hash}?s=#{size}&r=pg&d=#{CGI::escape(default)}"
  else
    default
  end
end
mark_spam() click to toggle source
# File lib/governor_comments/comment.rb, line 22
def mark_spam
  update_attribute(:hidden, true)
  spam! if respond_to?(:spam!)
end
not_spam() click to toggle source
# File lib/governor_comments/comment.rb, line 27
def not_spam
  update_attribute(:hidden, false)
  ham! if respond_to?(:ham!)
end