Class: Decidim::DecidimAwesome::Admin::RenameScopeLabel
- Defined in:
- app/commands/decidim/decidim_awesome/admin/rename_scope_label.rb
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(params, organization) ⇒ RenameScopeLabel
constructor
Public: Initializes the command.
Constructor Details
#initialize(params, organization) ⇒ RenameScopeLabel
Public: Initializes the command.
params - A constraint params
10 11 12 13 14 15 16 |
# File 'app/commands/decidim/decidim_awesome/admin/rename_scope_label.rb', line 10 def initialize(params, organization) @text = params[:text]&.strip&.gsub(" ", "_")&.parameterize&.truncate(64) @scope = params[:scope] @key = params[:key] @attribute = params[:attribute] @organization = 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.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/commands/decidim/decidim_awesome/admin/rename_scope_label.rb', line 24 def call raise StandardError, "empty value" if @text.blank? raise StandardError, "key already exists" if config.value.keys.include? @text transaction do config.value[@text] = config.value.delete @key config.save! if config_scope config_scope.var = scope config_scope.save! end end broadcast(:ok, { scope:, key: @text }) rescue StandardError => e broadcast(:invalid, e.) end |