Class: Enki::Comment

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

Constant Summary collapse

DEFAULT_LIMIT =
15

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PaginationShim

paginated, paginated_pages

Class Method Details

.build_for_preview(params) ⇒ Object



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

def build_for_preview(params)
  Comment.new_with_filter(params)
end

.find_recent(options = {}) ⇒ Object



67
68
69
70
71
72
# File 'app/models/enki/comment.rb', line 67

def find_recent(options = {})
  find(:all, {
    :limit => DEFAULT_LIMIT,
    :order => 'created_at DESC'
  }.merge(options))
end

.new_with_filter(params) ⇒ Object



56
57
58
59
60
61
# File 'app/models/enki/comment.rb', line 56

def new_with_filter(params)
  comment = Comment.new(params)
  comment.created_at = Time.now
  comment.apply_filter
  comment
end

.protected_attribute?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


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

def protected_attribute?(attribute)
  [:author, :body].include?(attribute.to_sym)
end

Instance Method Details

#apply_filterObject



17
18
19
# File 'app/models/enki/comment.rb', line 17

def apply_filter
  self.body_html = Lesstile.format_as_xhtml(self.body, :code_formatter => Lesstile::CodeRayFormatter)
end

#approved?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/enki/comment.rb', line 29

def approved?
  true
end

#denormalizeObject



33
34
35
# File 'app/models/enki/comment.rb', line 33

def denormalize
  self.post.denormalize_comments_count!
end

#destroy_with_undoObject



37
38
39
40
41
42
43
44
# File 'app/models/enki/comment.rb', line 37

def destroy_with_undo
  undo_item = nil
  transaction do
    self.destroy
    undo_item = DeleteCommentUndo.create_undo(self)
  end
  undo_item
end

#post_titleObject

Delegates



47
48
49
# File 'app/models/enki/comment.rb', line 47

def post_title
  post.title
end

#trusted_user?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'app/models/enki/comment.rb', line 21

def trusted_user?
  false
end

#user_logged_in?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/enki/comment.rb', line 25

def user_logged_in?
  false
end