Class: Refinery::Blog::Post
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Refinery::Blog::Post
- Extended by:
- FriendlyId
- Defined in:
- app/models/refinery/blog/post.rb
Defined Under Namespace
Modules: ShareThis
Class Method Summary collapse
- .by_archive(date) ⇒ Object
- .by_year(date) ⇒ Object
- .comments_allowed? ⇒ Boolean
- .next(current_record) ⇒ Object
- .popular(count) ⇒ Object
- .previous(item) ⇒ Object
- .published_before(date = Time.now) ⇒ Object (also: live)
- .published_dates_older_than(date) ⇒ Object
- .recent(count) ⇒ Object
- .teaser_enabled_toggle! ⇒ Object
- .teasers_enabled? ⇒ Boolean
- .uncategorized ⇒ Object
Instance Method Summary collapse
Class Method Details
.by_archive(date) ⇒ Object
56 57 58 |
# File 'app/models/refinery/blog/post.rb', line 56 def by_archive(date) where(:published_at => date.beginning_of_month..date.end_of_month) end |
.by_year(date) ⇒ Object
60 61 62 |
# File 'app/models/refinery/blog/post.rb', line 60 def by_year(date) where(:published_at => date.beginning_of_year..date.end_of_year) end |
.comments_allowed? ⇒ Boolean
93 94 95 |
# File 'app/models/refinery/blog/post.rb', line 93 def comments_allowed? Refinery::Setting.find_or_set(:comments_allowed, true, :scoping => 'blog') end |
.next(current_record) ⇒ Object
84 85 86 |
# File 'app/models/refinery/blog/post.rb', line 84 def next(current_record) where(["published_at > ? and draft = ?", current_record.published_at, false]).first end |
.popular(count) ⇒ Object
72 73 74 |
# File 'app/models/refinery/blog/post.rb', line 72 def popular(count) unscoped.order("access_count DESC").limit(count) end |
.previous(item) ⇒ Object
76 77 78 |
# File 'app/models/refinery/blog/post.rb', line 76 def previous(item) published_before(item.published_at).first end |
.published_before(date = Time.now) ⇒ Object Also known as: live
88 89 90 |
# File 'app/models/refinery/blog/post.rb', line 88 def published_before(date=Time.now) where("published_at < ? and draft = ?", date, false) end |
.published_dates_older_than(date) ⇒ Object
64 65 66 |
# File 'app/models/refinery/blog/post.rb', line 64 def published_dates_older_than(date) published_before(date).pluck(:published_at) end |
.recent(count) ⇒ Object
68 69 70 |
# File 'app/models/refinery/blog/post.rb', line 68 def recent(count) live.limit(count) end |
.teaser_enabled_toggle! ⇒ Object
101 102 103 104 |
# File 'app/models/refinery/blog/post.rb', line 101 def currently = Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'blog') Refinery::Setting.set(:teasers_enabled, :value => !currently, :scoping => 'blog') end |
.teasers_enabled? ⇒ Boolean
97 98 99 |
# File 'app/models/refinery/blog/post.rb', line 97 def Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'blog') end |
.uncategorized ⇒ Object
80 81 82 |
# File 'app/models/refinery/blog/post.rb', line 80 def uncategorized live.includes(:categories).where(:categories => { Refinery::Categorization.table_name => { :blog_category_id => nil } }) end |
Instance Method Details
#friendly_id_source ⇒ Object
51 52 53 |
# File 'app/models/refinery/blog/post.rb', line 51 def friendly_id_source custom_url.present? ? custom_url : title end |
#live? ⇒ Boolean
47 48 49 |
# File 'app/models/refinery/blog/post.rb', line 47 def live? !draft and published_at <= Time.now end |
#next ⇒ Object
39 40 41 |
# File 'app/models/refinery/blog/post.rb', line 39 def next self.class.next(self) end |
#prev ⇒ Object
43 44 45 |
# File 'app/models/refinery/blog/post.rb', line 43 def prev self.class.previous(self) end |