Class: SimpleForum::Topic
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SimpleForum::Topic
- Defined in:
- app/models/simple_forum/topic.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
Instance Method Summary collapse
- #author?(u) ⇒ Boolean
- #close! ⇒ Object
- #forum_must_be_topicable ⇒ Object
- #increment_views_count ⇒ Object
- #is_open ⇒ Object (also: #is_open?)
- #last_page ⇒ Object
- #open! ⇒ Object
-
#page_numbers(max = 5) ⇒ Object
return array with page numbers topic.page_numbers => [1, 2, 3, 4] #when pages count is 4 topic.page_numbers => [1, 2, 3, 4, 5] #when pages count is 5 topic.page_numbers => [1, nil, 3, 4, 5, 6] #when pages count is 6 topic.page_numbers => [1, nil, 4, 5, 6, 7] #when pages count is 7.
- #paged? ⇒ Boolean
- #to_param ⇒ Object
- #update_cached_post_fields(post) ⇒ Object
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
39 40 41 |
# File 'app/models/simple_forum/topic.rb', line 39 def body @body end |
Instance Method Details
#author?(u) ⇒ Boolean
83 84 85 |
# File 'app/models/simple_forum/topic.rb', line 83 def (u) user == u end |
#close! ⇒ Object
97 98 99 |
# File 'app/models/simple_forum/topic.rb', line 97 def close! update_attribute(:is_closed, true) end |
#forum_must_be_topicable ⇒ Object
30 31 32 |
# File 'app/models/simple_forum/topic.rb', line 30 def forum_must_be_topicable errors.add(:base, t('simple_forum.validations.forum_must_be_topicable')) if forum && !forum.is_topicable? end |
#increment_views_count ⇒ Object
101 102 103 |
# File 'app/models/simple_forum/topic.rb', line 101 def increment_views_count self.class.increment_counter(:views_count, self) end |
#is_open ⇒ Object Also known as: is_open?
87 88 89 |
# File 'app/models/simple_forum/topic.rb', line 87 def is_open !is_closed? end |
#last_page ⇒ Object
58 59 60 |
# File 'app/models/simple_forum/topic.rb', line 58 def last_page @last_page ||= [(posts.size.to_f / SimpleForum::Post.per_page).ceil.to_i, 1].max end |
#open! ⇒ Object
93 94 95 |
# File 'app/models/simple_forum/topic.rb', line 93 def open! update_attribute(:is_closed, false) end |
#page_numbers(max = 5) ⇒ Object
return array with page numbers topic.page_numbers => [1, 2, 3, 4] #when pages count is 4 topic.page_numbers => [1, 2, 3, 4, 5] #when pages count is 5 topic.page_numbers => [1, nil, 3, 4, 5, 6] #when pages count is 6 topic.page_numbers => [1, nil, 4, 5, 6, 7] #when pages count is 7
67 68 69 70 71 72 73 |
# File 'app/models/simple_forum/topic.rb', line 67 def page_numbers(max=5) if last_page > max [1] + [nil] + ((last_page-max+2)..last_page).to_a else (1..last_page).to_a end end |
#paged? ⇒ Boolean
54 55 56 |
# File 'app/models/simple_forum/topic.rb', line 54 def paged? posts.size > SimpleForum::Post.per_page end |
#to_param ⇒ Object
78 79 80 |
# File 'app/models/simple_forum/topic.rb', line 78 def to_param "#{id}-#{title.to_s.parameterize}" end |
#update_cached_post_fields(post) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/simple_forum/topic.rb', line 42 def update_cached_post_fields(post) if remaining_post = post.frozen? ? last_post : post self.class.update_all({:last_updated_at => remaining_post.created_at, :recent_post_id => remaining_post.id, # :posts_count => posts.size }, {:id => id}) forum.class.update_all({:recent_post_id => remaining_post.id}, {:id => forum.id}) else destroy end end |