Module: Decidim::Scopable
Overview
A concern with the components needed when you want a model to have a scope.
The including model needs to implement the following interface:
@abstract An instance method that returns the id of the scope
@method decidim_scope_id
@return [Integer]
@abstract An instance method that states whether scopes are enabled or not
@method scopes_enabled
@return [Boolean]
@abstract An method that gives an associated organization
@method organization
@return [Decidim::Organization]
Instance Method Summary collapse
-
#has_subscopes? ⇒ Boolean
Whether the resource has subscopes or not.
-
#out_of_scope?(subscope) ⇒ Boolean
Whether the passed subscope is out of the resource’s scope.
-
#subscopes ⇒ Object
Gets the children scopes of the object’s scope.
Instance Method Details
#has_subscopes? ⇒ Boolean
Whether the resource has subscopes or not.
Returns a boolean.
48 49 50 |
# File 'lib/decidim/scopable.rb', line 48 def has_subscopes? scopes_enabled && subscopes.any? end |
#out_of_scope?(subscope) ⇒ Boolean
Whether the passed subscope is out of the resource’s scope.
Returns a boolean
55 56 57 |
# File 'lib/decidim/scopable.rb', line 55 def out_of_scope?(subscope) scope && !scope.ancestor_of?(subscope) end |
#subscopes ⇒ Object
Gets the children scopes of the object’s scope.
If it’s global, returns the organization’s top scopes.
Returns an ActiveRecord::Relation.
41 42 43 |
# File 'lib/decidim/scopable.rb', line 41 def subscopes scope ? scope.children : organization.top_scopes end |