Class: UserBookmarkList

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serialization
Defined in:
app/models/user_bookmark_list.rb

Constant Summary collapse

PER_PAGE =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user:, guardian:, search_term: nil, per_page: nil, page: 0) ⇒ UserBookmarkList

Returns a new instance of UserBookmarkList.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/user_bookmark_list.rb', line 11

def initialize(user:, guardian:, search_term: nil, per_page: nil, page: 0)
  @user = user
  @guardian = guardian

  @per_page = per_page || PER_PAGE
  @per_page = PER_PAGE if @per_page > PER_PAGE

  @search_term = search_term
  @page = page.to_i

  @bookmarks = []
  @bookmark_serializer_opts = {}
end

Instance Attribute Details

#bookmark_serializer_optsObject

Returns the value of attribute bookmark_serializer_opts.



9
10
11
# File 'app/models/user_bookmark_list.rb', line 9

def bookmark_serializer_opts
  @bookmark_serializer_opts
end

#bookmarksObject (readonly)

Returns the value of attribute bookmarks.



8
9
10
# File 'app/models/user_bookmark_list.rb', line 8

def bookmarks
  @bookmarks
end

#has_moreObject (readonly)

Returns the value of attribute has_more.



8
9
10
# File 'app/models/user_bookmark_list.rb', line 8

def has_more
  @has_more
end

#more_bookmarks_urlObject

Returns the value of attribute more_bookmarks_url.



9
10
11
# File 'app/models/user_bookmark_list.rb', line 9

def more_bookmarks_url
  @more_bookmarks_url
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



8
9
10
# File 'app/models/user_bookmark_list.rb', line 8

def per_page
  @per_page
end

Instance Method Details

#load(&blk) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/user_bookmark_list.rb', line 25

def load(&blk)
  query =
    BookmarkQuery.new(
      user: @user,
      guardian: @guardian,
      search_term: @search_term,
      page: @page,
      per_page: @per_page,
    )

  @bookmarks = query.list_all(&blk)
  @has_more = (@page.to_i + 1) * @per_page < query.count
  @bookmarks
end