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.



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

def draft
  @draft
end

Class Method Details

.find_sti_class(type_name) ⇒ Object



7
8
9
# File 'app/models/content.rb', line 7

def self.find_sti_class(type_name)
  eval(type_name.to_s)
end

.primaryObject



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

def primary
  published.first
end

Instance Method Details

#author_id=(author_id) ⇒ Object



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

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



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

def category_titles
  categories.collect(&:title)
end

#draft?Boolean

Returns:

  • (Boolean)


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

def draft?
  published_at.nil?
end

#just_published?Boolean

Returns:

  • (Boolean)


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

def just_published?
  published? && published_at_changed?
end

#ownerObject



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

def owner
  section
end

#ownersObject



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

def owners
  owner.owners << owner
end

#pending?Boolean

Returns:

  • (Boolean)


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

def pending?
  !published?
end

#published?Boolean

Returns:

  • (Boolean)


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

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

#published_at=(published_at) ⇒ Object



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

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

#published_at?(date) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#published_monthObject



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

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

#published_yearObject



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

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

#stateObject



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

def state
  pending? ? :pending : :published
end

#to_paramObject



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

def to_param
  permalink
end