Sha256: 35f6cca217e4237340f8c51e9674bd8c01c5a78f76e9294a0949dcf4f9b458ae

Contents?: true

Size: 898 Bytes

Versions: 2

Compression:

Stored size: 898 Bytes

Contents

module Chive
  class Article < ApplicationRecord
    belongs_to :author, class_name: Chive.user_model, primary_key: Chive.user_pk_attr,
                        foreign_key: :author_id, required: false

    has_one_attached :image

    acts_as_taggable_on :tags

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

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

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

    def published?
    end

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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chive-0.1.1 app/models/chive/article.rb
chive-0.1.0 app/models/chive/article.rb