Class: Gluttonberg::Comment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/gluttonberg/comment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#blog_slugObject

Returns the value of attribute blog_slug.



22
23
24
# File 'app/models/gluttonberg/comment.rb', line 22

def blog_slug
  @blog_slug
end

#subscribe_to_commentsObject

Returns the value of attribute subscribe_to_comments.



22
23
24
# File 'app/models/gluttonberg/comment.rb', line 22

def subscribe_to_comments
  @subscribe_to_comments
end

Class Method Details

.all_comments_countObject



44
45
46
# File 'app/models/gluttonberg/comment.rb', line 44

def self.all_comments_count
  self.count
end

.approved_comments_countObject



48
49
50
# File 'app/models/gluttonberg/comment.rb', line 48

def self.approved_comments_count
  self.all_approved.count
end

.pending_comments_countObject



56
57
58
# File 'app/models/gluttonberg/comment.rb', line 56

def self.pending_comments_count
  self.all_pending.count
end

.rejected_comments_countObject



52
53
54
# File 'app/models/gluttonberg/comment.rb', line 52

def self.rejected_comments_count
  self.all_rejected.count
end

.spam_comments_countObject



60
61
62
# File 'app/models/gluttonberg/comment.rb', line 60

def self.spam_comments_count
  self.all_spam.count
end

.spam_detection_for_allObject



95
96
97
98
99
100
# File 'app/models/gluttonberg/comment.rb', line 95

def self.spam_detection_for_all
  self.all_pending.each do |c|
    c.send("spam_detection")
    c.save(:validate => false)
  end
end

Instance Method Details

#approved=(val) ⇒ Object



90
91
92
93
# File 'app/models/gluttonberg/comment.rb', line 90

def approved=(val)
  @approve_updated = !self.moderation_required && val && self.notification_sent_at.blank? #just got approved
  write_attribute(:approved, val)
end

#moderate(params) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/gluttonberg/comment.rb', line 29

def moderate(params)
    if params == "approve"
      self.moderation_required = false
      self.approved = true
      self.spam = false
      self.save
    elsif params == "disapprove"
      self.moderation_required = false
      self.approved = false
      self.save
    else
      #error
    end
end

#user_idObject



65
66
67
# File 'app/models/gluttonberg/comment.rb', line 65

def user_id
  self.author_id
end

#user_id=(new_id) ⇒ Object



69
70
71
# File 'app/models/gluttonberg/comment.rb', line 69

def user_id=(new_id)
  self.author_id=new_id
end

#writer_emailObject

these are helper methods for comment.



74
75
76
77
78
79
80
# File 'app/models/gluttonberg/comment.rb', line 74

def writer_email
  if self.author_email
    self.author_email
  elsif author
    author.email
  end
end

#writer_nameObject



82
83
84
85
86
87
88
# File 'app/models/gluttonberg/comment.rb', line 82

def writer_name
  if self.author_name
    self.author_name
  elsif author
    author.name
  end
end