Sha256: 584da5be201efacb6080b0bb7759aaa63895fdcae21c4b0ea460dc90391b1215

Contents?: true

Size: 777 Bytes

Versions: 36

Compression:

Stored size: 777 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # This concern contains the logic related to scopes.
  module Scopable
    extend ActiveSupport::Concern

    included do
      belongs_to :scope,
                 foreign_key: "decidim_scope_id",
                 class_name: "Decidim::Scope",
                 optional: true
    end

    # Gets the children scopes of the object's scope.
    #
    # If it's global, returns the organization's top scopes.
    #
    # Returns an ActiveRecord::Relation.
    def subscopes
      scope ? scope.children : organization.top_scopes
    end

    # Whether the resource has subscopes or not.
    #
    # Returns a boolean.
    def has_subscopes?
      scopes_enabled && subscopes.any?
    end
  end
end

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
decidim-core-0.9.3 lib/decidim/scopable.rb
decidim-core-0.9.2 lib/decidim/scopable.rb
decidim-core-0.9.1 lib/decidim/scopable.rb
decidim-core-0.9.0 lib/decidim/scopable.rb
decidim-core-0.8.4 lib/decidim/scopable.rb
decidim-core-0.8.3 lib/decidim/scopable.rb
decidim-core-0.8.2 lib/decidim/scopable.rb
decidim-core-0.8.1 lib/decidim/scopable.rb
decidim-core-0.8.0 lib/decidim/scopable.rb
decidim-core-0.7.4 lib/decidim/scopable.rb
decidim-core-0.7.3 lib/decidim/scopable.rb
decidim-core-0.7.2 lib/decidim/scopable.rb
decidim-core-0.7.1 lib/decidim/scopable.rb
decidim-core-0.7.0 lib/decidim/scopable.rb
decidim-core-0.6.8 lib/decidim/scopable.rb
decidim-0.6.8 decidim-core/lib/decidim/scopable.rb
decidim-core-0.6.7 lib/decidim/scopable.rb
decidim-0.6.7 decidim-core/lib/decidim/scopable.rb
decidim-core-0.6.6 lib/decidim/scopable.rb
decidim-0.6.6 decidim-core/lib/decidim/scopable.rb