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
- #bang_recent_activity(user) ⇒ Object
- #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
- #recent_activity?(user) ⇒ Boolean
- #to_param ⇒ Object
- #update_cached_post_fields(post) ⇒ Object
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
42 43 44 |
# File 'app/models/simple_forum/topic.rb', line 42 def body @body end |
Instance Method Details
#author?(u) ⇒ Boolean
86 87 88 |
# File 'app/models/simple_forum/topic.rb', line 86 def (u) user == u end |
#bang_recent_activity(user) ⇒ Object
108 109 110 |
# File 'app/models/simple_forum/topic.rb', line 108 def bang_recent_activity(user) SimpleForum::UserActivity.new(user).bang(self) end |
#close! ⇒ Object
100 101 102 |
# File 'app/models/simple_forum/topic.rb', line 100 def close! update_attribute(:is_closed, true) end |
#forum_must_be_topicable ⇒ Object
33 34 35 |
# File 'app/models/simple_forum/topic.rb', line 33 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
112 113 114 |
# File 'app/models/simple_forum/topic.rb', line 112 def increment_views_count self.class.increment_counter(:views_count, self) end |
#is_open ⇒ Object Also known as: is_open?
90 91 92 |
# File 'app/models/simple_forum/topic.rb', line 90 def is_open !is_closed? end |
#last_page ⇒ Object
61 62 63 |
# File 'app/models/simple_forum/topic.rb', line 61 def last_page @last_page ||= [(posts.size.to_f / SimpleForum::Post.per_page).ceil.to_i, 1].max end |
#open! ⇒ Object
96 97 98 |
# File 'app/models/simple_forum/topic.rb', line 96 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
70 71 72 73 74 75 76 |
# File 'app/models/simple_forum/topic.rb', line 70 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
57 58 59 |
# File 'app/models/simple_forum/topic.rb', line 57 def paged? posts.size > SimpleForum::Post.per_page end |
#recent_activity?(user) ⇒ Boolean
104 105 106 |
# File 'app/models/simple_forum/topic.rb', line 104 def recent_activity?(user) SimpleForum::UserActivity.new(user).recent_activity?(self) end |
#to_param ⇒ Object
81 82 83 |
# File 'app/models/simple_forum/topic.rb', line 81 def to_param "#{id}-#{title.to_s.parameterize}" end |
#update_cached_post_fields(post) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/simple_forum/topic.rb', line 45 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 |