Class: UserBookmarkList
- Inherits:
-
Object
- Object
- UserBookmarkList
- Includes:
- ActiveModel::Serialization
- Defined in:
- app/models/user_bookmark_list.rb
Constant Summary collapse
- PER_PAGE =
20
Instance Attribute Summary collapse
-
#bookmark_serializer_opts ⇒ Object
Returns the value of attribute bookmark_serializer_opts.
-
#bookmarks ⇒ Object
readonly
Returns the value of attribute bookmarks.
-
#has_more ⇒ Object
readonly
Returns the value of attribute has_more.
-
#more_bookmarks_url ⇒ Object
Returns the value of attribute more_bookmarks_url.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
Instance Method Summary collapse
- #categories ⇒ Object
-
#initialize(user:, guardian:, search_term: nil, per_page: nil, page: 0) ⇒ UserBookmarkList
constructor
A new instance of UserBookmarkList.
- #load(&blk) ⇒ Object
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_opts ⇒ Object
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 |
#bookmarks ⇒ Object (readonly)
Returns the value of attribute bookmarks.
8 9 10 |
# File 'app/models/user_bookmark_list.rb', line 8 def bookmarks @bookmarks end |
#has_more ⇒ Object (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_url ⇒ Object
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_page ⇒ Object (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
#categories ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/user_bookmark_list.rb', line 40 def categories @categories ||= @bookmarks .map do |bm| category = bm.bookmarkable.try(:category) || bm.bookmarkable.try(:topic)&.category [category&.parent_category, category] end .flatten .compact .uniq end |
#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 |