Class: Decidim::DecidimAwesome::Admin::UpdateMenuHack
- Defined in:
- app/commands/decidim/decidim_awesome/admin/update_menu_hack.rb
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form, menu_name) ⇒ UpdateMenuHack
constructor
Public: Initializes the command.
Constructor Details
#initialize(form, menu_name) ⇒ UpdateMenuHack
Public: Initializes the command.
9 10 11 12 |
# File 'app/commands/decidim/decidim_awesome/admin/update_menu_hack.rb', line 9 def initialize(form, ) @form = form @menu = AwesomeConfig.find_or_initialize_by(var: , 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 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/commands/decidim/decidim_awesome/admin/update_menu_hack.rb', line 20 def call return broadcast(:invalid) if form.invalid? .value = [] unless .value.is_a? Array .value = .value.filter { |i| i.is_a? Hash } found = false .value.map! do |item| if item["url"] == form.url found = true form.to_params else item end end .value << form.to_params unless found .save! broadcast(:ok, ) rescue StandardError => e broadcast(:invalid, e.) end |