Module: Crowdblog::User

Defined in:
app/models/crowdblog/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/crowdblog/user.rb', line 3

def self.included(base)
  base.send(:has_many, :authored_posts, inverse_of: :author,
      foreign_key: 'author_id', class_name: 'Crowdblog::Post')
  base.send(:has_many, :published_posts, -> {
        where(state: 'published').
        order('published_at DESC')
      },
      inverse_of: :author,
      foreign_key: 'author_id', class_name: 'Crowdblog::Post')
  base.send(:has_one, :last_post, -> {
        where(state: 'published').
        order('published_at DESC, created_at DESC, id DESC')
      },
      class_name: 'Crowdblog::Post',
      foreign_key: :author_id)
end

Instance Method Details

#is_publisher?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/models/crowdblog/user.rb', line 20

def is_publisher?
  true
end

#last_post_atObject



24
25
26
# File 'app/models/crowdblog/user.rb', line 24

def last_post_at
  last_post.try(:published_at)
end

#last_published_atObject



28
29
30
# File 'app/models/crowdblog/user.rb', line 28

def last_published_at
  published_posts.first ? published_posts.first.published_at : nil
end