Class: Decidim::Scope
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Scope
- Defined in:
- app/models/decidim/scope.rb
Overview
Scopes are used in some entities through Decidim to help users know which is the scope of a participatory process. (i.e. does it affect the whole city or just a district?)
Class Method Summary collapse
-
.top_level ⇒ Object
Scope to return only the top level scopes.
Instance Method Summary collapse
- #descendants ⇒ Object
-
#part_of_scopes ⇒ Object
Gets the scopes from the part_of list in descending order (first the top level scope, last itself).
Class Method Details
.top_level ⇒ Object
Scope to return only the top level scopes.
Returns an ActiveRecord::Relation.
41 42 43 |
# File 'app/models/decidim/scope.rb', line 41 def self.top_level where parent_id: nil end |
Instance Method Details
#descendants ⇒ Object
45 46 47 |
# File 'app/models/decidim/scope.rb', line 45 def descendants organization.scopes.where("? = ANY(decidim_scopes.part_of)", id) end |
#part_of_scopes ⇒ Object
Gets the scopes from the part_of list in descending order (first the top level scope, last itself)
Returns an array of Scope objects
52 53 54 |
# File 'app/models/decidim/scope.rb', line 52 def part_of_scopes organization.scopes.where(id: part_of).sort { |s1, s2| part_of.index(s2.id) <=> part_of.index(s1.id) } end |