Sha256: c0346da0e452824adf83eb3f3129646ed59769f73091c12d43f9247225eb140e

Contents?: true

Size: 568 Bytes

Versions: 6

Compression:

Stored size: 568 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

6 entries across 6 versions & 1 rubygems

Version Path
decidim-core-0.1.0 lib/decidim/has_scope.rb
decidim-core-0.0.8.1 lib/decidim/has_scope.rb
decidim-core-0.0.7 lib/decidim/has_scope.rb
decidim-core-0.0.6 lib/decidim/has_scope.rb
decidim-core-0.0.5 lib/decidim/has_scope.rb
decidim-core-0.0.3 lib/decidim/has_scope.rb