Class: Comment

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

Defined Under Namespace

Classes: CommentNotAllowed

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.approvedObject



4
5
6
# File 'app/models/comment.rb', line 4

def self.approved
  where :approved => true
end

.unapprovedObject



8
9
10
# File 'app/models/comment.rb', line 8

def self.unapproved
  where :approved => false
end

Instance Method Details

#around_saveObject



14
15
16
17
18
19
20
21
22
# File 'app/models/comment.rb', line 14

def around_save
  if just_approved?
    run_callbacks(:approve) { yield }
  elsif just_unapproved?
    run_callbacks(:unapprove) { yield }
  else
    yield
  end
end

#commentable_type=(sType) ⇒ Object

make sure we’re storing the base clase for STI



38
39
40
# File 'app/models/comment.rb', line 38

def commentable_type=(sType)
  super(sType.to_s.classify.constantize.base_class.to_s)
end

#filterObject



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

def filter
  commentable.comment_filter
end

#just_approved?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'app/models/comment.rb', line 63

def just_approved?
  approved_changed? and approved?
end

#just_unapproved?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/comment.rb', line 67

def just_unapproved?
  approved_changed? and unapproved?
end

#ownerObject



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

def owner
  commentable
end

#state_changesObject



71
72
73
74
75
76
77
78
# File 'app/models/comment.rb', line 71

def state_changes
  state_changes = if just_approved?
    [:approved]
  elsif just_unapproved?
    [:unapproved]
  end || []
  super + state_changes
end

#unapproved?Boolean

Returns:

  • (Boolean)


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

def unapproved?
  !approved?
end