Class: Decidim::DecidimAwesome::Admin::CreateCustomRedirect
- Inherits:
-
Command
- Object
- Command
- Command
- Decidim::DecidimAwesome::Admin::CreateCustomRedirect
- Defined in:
- app/commands/decidim/decidim_awesome/admin/create_custom_redirect.rb
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ CreateCustomRedirect
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ CreateCustomRedirect
Public: Initializes the command.
9 10 11 12 |
# File 'app/commands/decidim/decidim_awesome/admin/create_custom_redirect.rb', line 9 def initialize(form) @form = form @redirections = AwesomeConfig.find_or_initialize_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.
20 21 22 23 24 25 26 27 28 |
# File 'app/commands/decidim/decidim_awesome/admin/create_custom_redirect.rb', line 20 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_redirection! broadcast(:ok) rescue StandardError => e broadcast(:invalid, e.) end |