Sha256: cc9a7e79d388d3b78176a4eaa2d77fff0a254edc2bd11de241c5e20223be2299
Contents?: true
Size: 1.4 KB
Versions: 11
Compression:
Stored size: 1.4 KB
Contents
# frozen_string_literal: true module Decidim module DecidimAwesome module Admin class UpdateConfig < Command # Public: Initializes the command. # # form - A config 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 if form.invalid? message = form.errors[:scoped_styles].join("; ") if @form.errors[:scoped_styles].any? message = form.errors[:scoped_admins].join("; ") if @form.errors[:scoped_admins].any? return broadcast(:invalid, message, form.errors) end begin form.attributes.each do |key, val| # ignore nil attributes (must specifically be set to false if necessary) next unless form.valid_keys.include?(key.to_sym) setting = AwesomeConfig.find_or_initialize_by(var: key, organization: form.current_organization) setting.value = val.respond_to?(:attributes) ? val.attributes : val setting.save! end broadcast(:ok) rescue ActiveRecord::RecordInvalid => e broadcast(:invalid, e.message) end end attr_reader :form end end end end
Version data entries
11 entries across 11 versions & 1 rubygems