Sha256: be3356c102bc0c4199f69b43d8b4b2c6b94628f67a7dd1713e19f844087d3572

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Decidim
  module DecidimAwesome
    class AwesomeConfig < ApplicationRecord
      self.table_name = "decidim_awesome_config"

      belongs_to :organization, foreign_key: :decidim_organization_id, class_name: "Decidim::Organization"

      has_many :constraints,
               foreign_key: "decidim_awesome_config_id",
               class_name: "Decidim::DecidimAwesome::ConfigConstraint",
               dependent: :destroy

      validates :organization, presence: true
      validates :var, uniqueness: { scope: :decidim_organization_id }

      def additional_constraints
        @additional_constraints ||= []
      end

      def add_constraints(constraints)
        return if constraints.blank?

        additional_constraints.concat(constraints.respond_to?(:each) ? constraints : [constraints])
      end

      def self.for_organization(organization)
        where(organization: organization)
      end

      # use this instead of "constraints" to evaluate dynamically added constants
      def all_constraints
        constraints + additional_constraints
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
decidim-decidim_awesome-0.8.3 app/models/decidim/decidim_awesome/awesome_config.rb
decidim-decidim_awesome-0.8.2 app/models/decidim/decidim_awesome/awesome_config.rb
decidim-decidim_awesome-0.8.1 app/models/decidim/decidim_awesome/awesome_config.rb
decidim-decidim_awesome-0.8.0 app/models/decidim/decidim_awesome/awesome_config.rb
decidim-decidim_awesome-0.7.2 app/models/decidim/decidim_awesome/awesome_config.rb