Class: PostType

Inherits:
ApplicationRecord show all
Defined in:
app/models/post_type.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

#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_cacheObject



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

.mappingObject



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_levelObject



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_levelObject



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

#reactionsObject



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.

Returns:

  • (Boolean)

    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