module Miniblog::User

Public Class Methods

included(base) click to toggle source
# File app/models/miniblog/user.rb, line 3
def self.included(base)
  base.send(:has_many, :authored_posts, inverse_of: :author,
      foreign_key: 'author_id', class_name: 'Miniblog::Post')
  base.send(:has_many, :published_posts, -> {
        where(state: 'published').
        order('published_at DESC')
      },
      inverse_of: :author,
      foreign_key: 'author_id', class_name: 'Miniblog::Post')
  base.send(:has_one, :last_post, -> {
        where(state: 'published').
        order('published_at DESC, created_at DESC, id DESC')
      },
      class_name: 'Miniblog::Post',
      foreign_key: :author_id)
end

Public Instance Methods

is_publisher?() click to toggle source
# File app/models/miniblog/user.rb, line 20
def is_publisher?
  true
end
last_post_at() click to toggle source
# File app/models/miniblog/user.rb, line 24
def last_post_at
  last_post.try(:published_at)
end
last_published_at() click to toggle source
# File app/models/miniblog/user.rb, line 28
def last_published_at
  published_posts.first ? published_posts.first.published_at : nil
end