Class: Content

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/content.rb

Direct Known Subclasses

Article, Link

Defined Under Namespace

Classes: Version

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#draftObject

Returns the value of attribute draft.



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

def draft
  @draft
end

Class Method Details

.primaryObject



58
59
60
# File 'app/models/content.rb', line 58

def primary
  published.first
end

Instance Method Details

#author_id=(author_id) ⇒ Object



84
85
86
87
# File 'app/models/content.rb', line 84

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



75
76
77
# File 'app/models/content.rb', line 75

def category_titles
  categories.collect(&:title)
end

#diff_against_version(version) ⇒ Object



121
122
123
124
125
# File 'app/models/content.rb', line 121

def diff_against_version(version)
  # return '(orginal version)' if version == versions.earliest.version
  version = versions[version]
  HtmlDiff.diff(version.excerpt_html + version.body_html, excerpt_html + body_html)
end

#draft?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'app/models/content.rb', line 97

def draft?
  published_at.nil?
end

#just_published?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'app/models/content.rb', line 117

def just_published?
  published? && published_at_changed?
end

#ownerObject



71
72
73
# File 'app/models/content.rb', line 71

def owner
  section
end

#ownersObject



67
68
69
# File 'app/models/content.rb', line 67

def owners
  owner.owners << owner
end

#pending?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'app/models/content.rb', line 101

def pending?
  !published?
end

#published?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'app/models/content.rb', line 105

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

#published_at=(published_at) ⇒ Object



80
81
82
# File 'app/models/content.rb', line 80

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

#published_at?(date) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
# File 'app/models/content.rb', line 109

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

#published_monthObject



93
94
95
# File 'app/models/content.rb', line 93

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

#published_yearObject



89
90
91
# File 'app/models/content.rb', line 89

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

#stateObject



113
114
115
# File 'app/models/content.rb', line 113

def state
  pending? ? :pending : :published
end

#to_paramObject



63
64
65
# File 'app/models/content.rb', line 63

def to_param
  permalink
end