Class: Refinery::News::Item
- Inherits:
-
Core::BaseModel
- Object
- Core::BaseModel
- Refinery::News::Item
- Extended by:
- FriendlyId
- Defined in:
- app/models/refinery/news/item.rb
Defined Under Namespace
Classes: Translation
Instance Attribute Summary collapse
-
#locale ⇒ Object
to hold temporarily.
Class Method Summary collapse
- .all_previous ⇒ Object
- .by_archive(archive_date) ⇒ Object
- .by_year(archive_year) ⇒ Object
- .latest(limit = 10) ⇒ Object
- .live ⇒ Object
- .next(item) ⇒ Object
- .not_expired ⇒ Object
- .previous(item) ⇒ Object
- .published ⇒ Object
- .teaser_enabled_toggle! ⇒ Object
- .teasers_enabled? ⇒ Boolean
-
.translated ⇒ Object
rejects any page that has not been translated to the current locale.
Instance Method Summary collapse
- #next ⇒ Object
-
#not_published? ⇒ Boolean
has the published date not yet arrived?.
- #prev ⇒ Object
Instance Attribute Details
#locale ⇒ Object
to hold temporarily
8 9 10 |
# File 'app/models/refinery/news/item.rb', line 8 def locale @locale end |
Class Method Details
.all_previous ⇒ Object
45 46 47 |
# File 'app/models/refinery/news/item.rb', line 45 def all_previous where(['publish_date <= ?', Time.now.beginning_of_month]) end |
.by_archive(archive_date) ⇒ Object
37 38 39 |
# File 'app/models/refinery/news/item.rb', line 37 def by_archive(archive_date) where(['publish_date between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]) end |
.by_year(archive_year) ⇒ Object
41 42 43 |
# File 'app/models/refinery/news/item.rb', line 41 def by_year(archive_year) where(['publish_date between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year]) end |
.latest(limit = 10) ⇒ Object
67 68 69 |
# File 'app/models/refinery/news/item.rb', line 67 def latest(limit = 10) published.limit(limit) end |
.live ⇒ Object
71 72 73 |
# File 'app/models/refinery/news/item.rb', line 71 def live not_expired.where( "publish_date <= ?", Time.now) end |
.next(item) ⇒ Object
49 50 51 52 53 |
# File 'app/models/refinery/news/item.rb', line 49 def next(item) self.send(:with_exclusive_scope) do where("publish_date > ?", item.publish_date).order("publish_date ASC") end end |
.not_expired ⇒ Object
59 60 61 |
# File 'app/models/refinery/news/item.rb', line 59 def not_expired where(arel_table[:expiration_date].eq(nil).or(arel_table[:expiration_date].gt(Time.now))) end |
.previous(item) ⇒ Object
55 56 57 |
# File 'app/models/refinery/news/item.rb', line 55 def previous(item) where("publish_date < ?", item.publish_date) end |
.published ⇒ Object
63 64 65 |
# File 'app/models/refinery/news/item.rb', line 63 def published not_expired.where("publish_date < ?", Time.now) end |
.teaser_enabled_toggle! ⇒ Object
88 89 90 91 |
# File 'app/models/refinery/news/item.rb', line 88 def currently = Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'news') Refinery::Setting.set(:teasers_enabled, :value => !currently, :scoping => 'news') end |
.teasers_enabled? ⇒ Boolean
84 85 86 |
# File 'app/models/refinery/news/item.rb', line 84 def Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'news') end |
.translated ⇒ Object
rejects any page that has not been translated to the current locale.
76 77 78 79 80 81 82 |
# File 'app/models/refinery/news/item.rb', line 76 def translated includes(:translations).where( translation_class.arel_table[:locale].eq(::Globalize.locale) ).where( arel_table[:id].eq(translation_class.arel_table[:refinery_news_item_id]) ) end |
Instance Method Details
#next ⇒ Object
28 29 30 |
# File 'app/models/refinery/news/item.rb', line 28 def next self.class.next(self).first end |
#not_published? ⇒ Boolean
has the published date not yet arrived?
24 25 26 |
# File 'app/models/refinery/news/item.rb', line 24 def not_published? # has the published date not yet arrived? publish_date > Time.now end |
#prev ⇒ Object
32 33 34 |
# File 'app/models/refinery/news/item.rb', line 32 def prev self.class.previous(self).first end |