Class: Decidim::DecidimAwesome::Admin::CreateCustomRedirect

Inherits:
Command
  • Object
show all
Includes:
NeedsConstraintHelpers
Defined in:
app/commands/decidim/decidim_awesome/admin/create_custom_redirect.rb

Instance Method Summary collapse

Constructor Details

#initialize(form) ⇒ CreateCustomRedirect

Public: Initializes the command.



10
11
12
13
14
15
# File 'app/commands/decidim/decidim_awesome/admin/create_custom_redirect.rb', line 10

def initialize(form)
  @form = form
  @ident = form.to_params[0]
  @organization = form.current_organization
  @config_var = :custom_redirects
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if we couldn’t proceed.

Returns nothing.



23
24
25
26
27
28
29
30
31
32
# File 'app/commands/decidim/decidim_awesome/admin/create_custom_redirect.rb', line 23

def call
  return broadcast(:invalid) if form.invalid?
  return broadcast(:invalid, I18n.t("custom_redirects.origin_exists", scope: "decidim.decidim_awesome.admin")) if url_exists?

  create_hash_config!(form.to_params[1])

  broadcast(:ok)
rescue StandardError => e
  broadcast(:invalid, e.message)
end