Class: PostType
Class Method Summary
collapse
Instance Method Summary
collapse
#attributes_print, fuzzy_search, match_search, #match_search, sanitize_for_search, sanitize_name, sanitize_sql_in, useful_err_msg, with_lax_group_rules
Class Method Details
.[](key) ⇒ Object
37
38
39
|
# File 'app/models/post_type.rb', line 37
def self.[](key)
PostType.find_by(name: key)
end
|
.clear_ids_cache ⇒ Object
27
28
29
|
# File 'app/models/post_type.rb', line 27
def self.clear_ids_cache
Rails.cache.delete 'network/post_types/post_type_ids', include_community: false
end
|
.mapping ⇒ Object
31
32
33
34
35
|
# File 'app/models/post_type.rb', line 31
def self.mapping
Rails.cache.fetch 'network/post_types/post_type_ids', include_community: false do
PostType.all.to_h { |pt| [pt.name, pt.id] }
end
end
|
.second_level ⇒ Object
47
48
49
50
51
|
# File 'app/models/post_type.rb', line 47
def self.second_level
Rails.cache.fetch 'network/post_types/second_level', include_community: false do
where(is_top_level: false)
end
end
|
.top_level ⇒ Object
41
42
43
44
45
|
# File 'app/models/post_type.rb', line 41
def self.top_level
Rails.cache.fetch 'network/post_types/top_level', include_community: false do
where(is_top_level: true)
end
end
|
Instance Method Details
#reactions ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
|
# File 'app/models/post_type.rb', line 10
def reactions
Rails.cache.fetch "post_type/#{name}/reactions" do
return [] unless has_reactions
if has_only_specific_reactions
ReactionType.active.where(post_type: self)
else
ReactionType.active.where(post_type: self).or(ReactionType.active.where(post_type: nil))
end.order(position: :asc).all
end
end
|
#system? ⇒ Boolean
Returns whether the post type is a system type.
23
24
25
|
# File 'app/models/post_type.rb', line 23
def system?
['HelpDoc', 'PolicyDoc'].include?(name)
end
|