Sha256: 30faf791b5e978f956d6aad13e71c7b458efbcf67ae3215435e73b1d7a0d8864

Contents?: true

Size: 571 Bytes

Versions: 1

Compression:

Stored size: 571 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # A concern with the features needed when you want a model to be have a scope.
  module HasScope
    extend ActiveSupport::Concern

    included do
      belongs_to :scope, foreign_key: "decidim_scope_id", class_name: "Decidim::Scope"
      validate :scope_belongs_to_organization

      private

      def scope_belongs_to_organization
        return if !scope || !feature
        errors.add(:scope, :invalid) unless feature.scopes.where(id: scope.id).exists?
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
decidim-core-0.2.0 lib/decidim/has_scope.rb