Class: Decidim::DecidimAwesome::Admin::DestroyMenuHack

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

Instance Method Summary collapse

Constructor Details

#initialize(item, menu_name, organization) ⇒ DestroyMenuHack

Public: Initializes the command.

item - the menu item to destroy organization



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

def initialize(item, menu_name, organization)
  @item = item
  @organization = organization
  @menu = AwesomeConfig.find_by(var: menu_name, organization:)
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/destroy_menu_hack.rb', line 23

def call
  return broadcast(:invalid) unless url_exists?

  menu.value&.reject! { |i| i["url"] == item.url }
  menu.save!

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