Class: PostGroup
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- PostGroup
- Includes:
- Checkable, FlatPriority, RequiredUniqueName, RequiredUniqueSlug, Toggleable
- Defined in:
- app/models/post_group.rb
Overview
Model for post category group
Attributes:
created_at [DateTime]
name [String]
nav_text [String]
priority [Integer]
slug [String]
updated_at [DateTime]
visible [Boolean]
Constant Summary collapse
- NAME_LIMIT =
50
- NAV_TEXT_LIMIT =
50
- SLUG_LIMIT =
30
- SLUG_PATTERN =
/\A[a-z][-_0-9a-z]+[a-z0-9]\z/.freeze
- SLUG_PATTERN_HTML =
'^[a-zA-Z][-_0-9a-zA-Z]+[a-zA-Z0-9]$'
Class Method Summary collapse
Instance Method Summary collapse
- #add_category(entity) ⇒ Object
- #add_tag(entity) ⇒ Object
- #category?(entity) ⇒ Boolean
- #posts_page(page = 1) ⇒ Object
- #remove_category(entity) ⇒ Object
- #remove_tag(entity) ⇒ Object
- #tag?(entity) ⇒ Boolean
Class Method Details
.[](slug) ⇒ Object
44 45 46 |
# File 'app/models/post_group.rb', line 44 def self.[](slug) find_by(slug: slug) end |
.entity_parameters ⇒ Object
39 40 41 |
# File 'app/models/post_group.rb', line 39 def self.entity_parameters %i[name nav_text priority slug visible] end |
Instance Method Details
#add_category(entity) ⇒ Object
49 50 51 |
# File 'app/models/post_group.rb', line 49 def add_category(entity) post_group_categories.create(post_category: entity) end |
#add_tag(entity) ⇒ Object
64 65 66 |
# File 'app/models/post_group.rb', line 64 def add_tag(entity) .create(post_tag: entity) end |
#category?(entity) ⇒ Boolean
59 60 61 |
# File 'app/models/post_group.rb', line 59 def category?(entity) post_group_categories.where(post_category: entity).exists? end |
#posts_page(page = 1) ⇒ Object
79 80 81 82 83 |
# File 'app/models/post_group.rb', line 79 def posts_page(page = 1) post_ids = Post.where(post_category_id: post_category_ids).pluck(:id) post_ids += PostPostTag.where(post_tag_id: post_tag_ids).pluck(:post_id) Post.list_for_visitors.where(id: post_ids.uniq).page(page) end |
#remove_category(entity) ⇒ Object
54 55 56 |
# File 'app/models/post_group.rb', line 54 def remove_category(entity) post_group_categories.where(post_category: entity).delete_all end |
#remove_tag(entity) ⇒ Object
69 70 71 |
# File 'app/models/post_group.rb', line 69 def remove_tag(entity) .where(post_tag: entity).delete_all end |
#tag?(entity) ⇒ Boolean
74 75 76 |
# File 'app/models/post_group.rb', line 74 def tag?(entity) .where(post_tag: entity).exists? end |