Class: Decidim::Scope

Inherits:
ApplicationRecord show all
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

Instance Method Summary collapse

Class Method Details

.top_levelObject

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

#descendantsObject



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_scopesObject

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