Class: Refinery::News::Item

Inherits:
Core::BaseModel
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/refinery/news/item.rb

Defined Under Namespace

Classes: Translation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#localeObject

to hold temporarily



8
9
10
# File 'app/models/refinery/news/item.rb', line 8

def locale
  @locale
end

Class Method Details

.all_previousObject



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

.liveObject



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_expiredObject



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

.publishedObject



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 teaser_enabled_toggle!
  currently = Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'news')
  Refinery::Setting.set(:teasers_enabled, :value => !currently, :scoping => 'news')
end

.teasers_enabled?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'app/models/refinery/news/item.rb', line 84

def teasers_enabled?
  Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'news')
end

.translatedObject

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

#nextObject



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?

Returns:

  • (Boolean)


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

#prevObject



32
33
34
# File 'app/models/refinery/news/item.rb', line 32

def prev
  self.class.previous(self).first
end