Sha256: d4f035baf5f34b384658eb9a7ac6d4f83283c8f80f3300247bbd33e79fba5451
Contents?: true
Size: 1.22 KB
Versions: 15
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true module Decidim module DecidimAwesome module Admin class CreateConstraint < Rectify::Command # Public: Initializes the command. # # form - A constraint form def initialize(form) @form = form end # Executes the command. Broadcasts these events: # # - :ok when everything is valid. # - :invalid if we couldn't proceed. # # Returns nothing. def call return broadcast(:invalid) if form.invalid? return broadcast(:invalid) if attributes.blank? begin @constraint = ConfigConstraint.create!( awesome_config: form.context.setting, settings: attributes ) broadcast(:ok, @constraint) rescue ActiveRecord::RecordNotUnique broadcast(:invalid, I18n.t("decidim.decidim_awesome.admin.constraints.errors.not_unique")) rescue StandardError => e broadcast(:invalid, e.message) end end private attr_reader :form, :constraint def attributes form.attributes.filter { |_i, v| v.present? } end end end end end
Version data entries
15 entries across 15 versions & 1 rubygems