Class: Content

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Adva::BelongsToAuthor, Adva::HasPermalink
Defined in:
app/models/content.rb

Direct Known Subclasses

Article, Link

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Adva::BelongsToAuthor

included

Methods included from Adva::HasPermalink

included

Instance Attribute Details

#draftObject

Returns the value of attribute draft.



77
78
79
# File 'app/models/content.rb', line 77

def draft
  @draft
end

Class Method Details

.primaryObject



56
57
58
# File 'app/models/content.rb', line 56

def primary
  published.first
end

Instance Method Details

#author_id=(author_id) ⇒ Object



82
83
84
85
# File 'app/models/content.rb', line 82

def author_id=(author_id)
  # FIXME this is only needed because belongs_to_cacheable can't be non-polymorphic, yet
  self.author = User.find(author_id) if author_id
end

#category_titlesObject



73
74
75
# File 'app/models/content.rb', line 73

def category_titles
  categories.collect(&:title)
end

#draft?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/models/content.rb', line 95

def draft?
  published_at.nil?
end

#just_published?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'app/models/content.rb', line 115

def just_published?
  published? && published_at_changed?
end

#ownerObject



69
70
71
# File 'app/models/content.rb', line 69

def owner
  section
end

#ownersObject



65
66
67
# File 'app/models/content.rb', line 65

def owners
  owner.owners << owner
end

#pending?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'app/models/content.rb', line 99

def pending?
  !published?
end

#published?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'app/models/content.rb', line 103

def published?
  !published_at.nil? && published_at <= Time.zone.now
end

#published_at=(published_at) ⇒ Object



78
79
80
# File 'app/models/content.rb', line 78

def published_at=(published_at)
  write_attribute(:published_at, draft.to_i == 1 ? nil : published_at)
end

#published_at?(date) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
# File 'app/models/content.rb', line 107

def published_at?(date)
  published? && date == [:year, :month, :day].map { |key| published_at.send(key).to_s }
end

#published_monthObject



91
92
93
# File 'app/models/content.rb', line 91

def published_month
  Time.local(published_at.year, published_at.month, 1)
end

#published_yearObject



87
88
89
# File 'app/models/content.rb', line 87

def published_year
  Time.local(published_at.year, 1, 1)
end

#stateObject



111
112
113
# File 'app/models/content.rb', line 111

def state
  pending? ? :pending : :published
end

#to_paramObject



61
62
63
# File 'app/models/content.rb', line 61

def to_param
  permalink
end