Class: Chive::Article

Inherits:
ApplicationRecord show all
Defined in:
app/models/chive/article.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.latestObject



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

def self.latest
  self.order(published_at: :desc, created_at: :desc)
end

.latest_publishedObject



62
63
64
65
# File 'app/models/chive/article.rb', line 62

def self.latest_published
  now = DateTime.now
  latest.where('published_at <= ? AND (expired_at >= ? OR expired_at IS NULL) AND status = ?', now, now, 'publish')
end

Instance Method Details

#bylineObject



20
21
22
23
24
# File 'app/models/chive/article.rb', line 20

def 
  return  if .present?
  return real_author_name if real_author_name.present?
  Chive.anonymous_name
end

#draft?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/chive/article.rb', line 42

def draft?
  self.status == 'draft'
end

#expired?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'app/models/chive/article.rb', line 34

def expired?
  expired_at && expired_at <= DateTime.now
end

#pending?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/models/chive/article.rb', line 30

def pending?
  published_at > DateTime.now
end

#public?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/models/chive/article.rb', line 46

def public?
  self.status == 'publish' && !pending? && !expired?
end

#published?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'app/models/chive/article.rb', line 38

def published?
  self.status == 'publish'
end

#real_author_nameObject



26
27
28
# File 'app/models/chive/article.rb', line 26

def real_author_name
  author.present? && author.send(Chive.user_name_attr)
end

#set_slugObject



54
55
56
# File 'app/models/chive/article.rb', line 54

def set_slug
  self.slug = Chive.slug_formatter.call(self) if slug.blank?
end

#to_paramObject



50
51
52
# File 'app/models/chive/article.rb', line 50

def to_param
  slug
end