module Decidim::ScopableComponent

This concern contains the logic related to scopes included by components.

Public Instance Methods

has_subscopes?() click to toggle source

Whether the component or participatory_space has subscopes or not.

Returns a boolean.

# File lib/decidim/scopable_component.rb, line 18
def has_subscopes?
  (scopes_enabled? || participatory_space.scopes_enabled?) && subscopes.any?
end
scope() click to toggle source

Public: Returns the component Scope

# File lib/decidim/scopable_component.rb, line 23
def scope
  return participatory_space.scope unless scopes_enabled?

  participatory_space.scopes.find_by(id: settings.scope_id)
end
scope_belongs_to_participatory_space() click to toggle source

Validation to ensure that the component is scoped within its participatory space Scope.

# File lib/decidim/scopable_component.rb, line 37
def scope_belongs_to_participatory_space
  return if !scopes_enabled? || !participatory_space

  errors.add(:scope, :invalid) if participatory_space.out_of_scope?(scope)
end
scopes_enabled() click to toggle source

Returns a boolean.

# File lib/decidim/scopable_component.rb, line 30
def scopes_enabled
  settings.try(:scopes_enabled)
end