Class: Decidim::SpamSignal::Admin::UpdateCopCommand

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, settings_repo, form) ⇒ UpdateCopCommand

Returns a new instance of UpdateCopCommand.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
# File 'app/commands/decidim/spam_signal/admin/update_cop_command.rb', line 11

def initialize(config, settings_repo, form)
  @current_config = config
  @settings_repo = settings_repo
  @form = form
  raise ArgumentError, "missing current_config" unless current_config
  raise ArgumentError, "missing settings_repo" unless settings_repo
end

Instance Attribute Details

#current_configObject (readonly)

Returns the value of attribute current_config.



7
8
9
# File 'app/commands/decidim/spam_signal/admin/update_cop_command.rb', line 7

def current_config
  @current_config
end

#formObject (readonly)

Returns the value of attribute form.



7
8
9
# File 'app/commands/decidim/spam_signal/admin/update_cop_command.rb', line 7

def form
  @form
end

#settings_repoObject (readonly)

Returns the value of attribute settings_repo.



7
8
9
# File 'app/commands/decidim/spam_signal/admin/update_cop_command.rb', line 7

def settings_repo
  @settings_repo
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/commands/decidim/spam_signal/admin/update_cop_command.rb', line 19

def call
  return broadcast(:invalid) if form.invalid?
  begin
    settings_repo.set_cop(
      { **attributes, "handler_name" => form.handler_name, "type" => form.context.type }
    )
    current_config.save_settings
    broadcast(:ok, settings_repo)
  rescue StandardError => e
    broadcast(:invalid, e.message)
  end
end