Sha256: d2fd0b70fe3f96e504f2168d986c787ad67f969181ddc5147b17f981c4e265f4

Contents?: true

Size: 766 Bytes

Versions: 3

Compression:

Stored size: 766 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module Notify
    # A concern with the components needed when you want a model to be have a questionnaire attached
    module BelongsToNotifyComponent
      extend ActiveSupport::Concern

      included do
        belongs_to :component, foreign_key: "decidim_component_id", class_name: "Decidim::Component"

        validates :component, presence: true
        validate :component_is_notify

        def self.for(component)
          where(component: component)
        end

        private

        def component_is_notify
          return unless component

          errors.add(:component, :invalid) unless component.manifest.name == :notify
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-notify-0.5 app/models/concerns/decidim/notify/belongs_to_notify_component.rb
decidim-notify-0.4 app/models/concerns/decidim/notify/belongs_to_notify_component.rb
decidim-notify-0.3 app/models/concerns/decidim/notify/belongs_to_notify_component.rb