Class: Decidim::Voca::Organization::UpdateColorCommand

Inherits:
OrganizationCommand show all
Defined in:
app/commands/decidim/voca/organization/update_color_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from OrganizationCommand

#command_name, command_name, #organization

Constructor Details

#initialize(color_settings) ⇒ UpdateColorCommand

Returns a new instance of UpdateColorCommand.



6
7
8
# File 'app/commands/decidim/voca/organization/update_color_command.rb', line 6

def initialize(color_settings)
  @color_settings = with_defaults(color_settings.to_h.with_indifferent_access)
end

Instance Attribute Details

#color_settingsObject (readonly)

Returns the value of attribute color_settings.



5
6
7
# File 'app/commands/decidim/voca/organization/update_color_command.rb', line 5

def color_settings
  @color_settings
end

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
18
# File 'app/commands/decidim/voca/organization/update_color_command.rb', line 10

def call
  organization.update!(
    colors: (organization.colors || []).merge(color_settings.delete_if { |_k, v| v.blank? })
    )
  broadcast(:ok)
rescue e
  Rails.logger.error(e)
  broadcast(:fail)
end