Module: GovernorComments::Comment

Defined in:
lib/governor_comments/comment.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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

Instance Method Details

#gravatar_url(size = 48, default = "http://github.com/images/gravatars/gravatar-#{size}.png") ⇒ Object



32
33
34
35
36
37
38
39
# 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_spamObject



22
23
24
25
# File 'lib/governor_comments/comment.rb', line 22

def mark_spam
  update_attribute(:hidden, true)
  spam! if respond_to?(:spam!)
end

#not_spamObject



27
28
29
30
# File 'lib/governor_comments/comment.rb', line 27

def not_spam
  update_attribute(:hidden, false)
  ham! if respond_to?(:ham!)
end