Sha256: a652ced5229f35be1305701346266b3b14a2da963ea77426f143c5ad0770e175
Contents?: true
Size: 1.15 KB
Versions: 58
Compression:
Stored size: 1.15 KB
Contents
# frozen_string_literal: true require "active_support/concern" module Decidim # This concern contains the logic related to scopes included by components. module ScopableComponent extend ActiveSupport::Concern included do include Scopable validate :scope_belongs_to_participatory_space # Whether the component or participatory_space has subscopes or not. # # Returns a boolean. def has_subscopes? (scopes_enabled? || participatory_space.scopes_enabled?) && subscopes.any? end # Public: Returns the component Scope def scope return participatory_space.scope unless scopes_enabled? participatory_space.scopes.find_by(id: settings.scope_id) end # Returns a boolean. def scopes_enabled settings.try(:scopes_enabled) end private # Validation to ensure that the component is scoped within its participatory space Scope. def scope_belongs_to_participatory_space return if !scopes_enabled? || !participatory_space errors.add(:scope, :invalid) if participatory_space.out_of_scope?(scope) end end end end
Version data entries
58 entries across 58 versions & 1 rubygems