Class: Decidim::DecidimAwesome::Admin::UpdateCustomRedirect
- Inherits:
-
Command
- Object
- Command
- Command
- Decidim::DecidimAwesome::Admin::UpdateCustomRedirect
- Defined in:
- app/commands/decidim/decidim_awesome/admin/update_custom_redirect.rb
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form, item) ⇒ UpdateCustomRedirect
constructor
Public: Initializes the command.
Constructor Details
#initialize(form, item) ⇒ UpdateCustomRedirect
Public: Initializes the command.
9 10 11 12 13 |
# File 'app/commands/decidim/decidim_awesome/admin/update_custom_redirect.rb', line 9 def initialize(form, item) @form = form @item = item @redirects = AwesomeConfig.find_by(var: :custom_redirects, organization: form.current_organization) end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if we couldn’t proceed.
Returns nothing.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/commands/decidim/decidim_awesome/admin/update_custom_redirect.rb', line 21 def call return broadcast(:invalid) if form.invalid? return broadcast(:invalid, I18n.t("custom_redirects.origin_missing", scope: "decidim.decidim_awesome.admin")) unless url_exists? redirects.value&.except!(item.origin) redirects.value[to_params[0]] = to_params[1] redirects.save! broadcast(:ok, redirects) rescue StandardError => e broadcast(:invalid, e.) end |