Class: Decidim::Category

Inherits:
ApplicationRecord show all
Includes:
FilterableResource, Traceable, TranslatableResource
Defined in:
decidim-core/app/models/decidim/category.rb

Overview

Categories serve as a taxonomy for components to use for while in the context of a participatory process.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.first_classObject

Scope to return only the first-class categories, that is, those that are not subcategories.

Returns an ActiveRecord::Relation.



27
28
29
# File 'decidim-core/app/models/decidim/category.rb', line 27

def self.first_class
  where(parent_id: nil)
end

.log_presenter_class_for(_log) ⇒ Object



43
44
45
# File 'decidim-core/app/models/decidim/category.rb', line 43

def self.log_presenter_class_for(_log)
  Decidim::AdminLog::CategoryPresenter
end

Instance Method Details

#descendantsObject



31
32
33
# File 'decidim-core/app/models/decidim/category.rb', line 31

def descendants
  @descendants ||= Category.where(parent_id: id)
end

#translated_nameObject



35
36
37
# File 'decidim-core/app/models/decidim/category.rb', line 35

def translated_name
  Decidim::CategoryPresenter.new(self).translated_name
end

#unused?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'decidim-core/app/models/decidim/category.rb', line 39

def unused?
  categorizations.empty?
end