Class: Decidim::Commands::UpdateResource

Inherits:
Decidim::Command show all
Includes:
ResourceHandler
Defined in:
decidim-core/lib/decidim/commands/update_resource.rb

Direct Known Subclasses

Accountability::Admin::UpdateImportedResult, Accountability::Admin::UpdateResult, Accountability::Admin::UpdateStatus, Accountability::Admin::UpdateTimelineEntry, Admin::UpdateArea, Admin::UpdateAreaType, Admin::UpdateCategory, Admin::UpdateComponent, Admin::UpdateOrganization, Admin::UpdateOrganizationAppearance, Admin::UpdateScope, Admin::UpdateScopeType, Admin::UpdateShareToken, Admin::UpdateStaticPage, Admin::UpdateStaticPageTopic, Admin::UpdateTaxonomy, Admin::UpdateTaxonomyFilter, Assemblies::Admin::UpdateAssembliesType, Assemblies::Admin::UpdateAssembly, Assemblies::Admin::UpdateAssemblyMember, Blogs::Admin::UpdatePost, Budgets::Admin::UpdateBudget, Budgets::Admin::UpdateProject, Decidim::Conferences::Admin::UpdateConference, Decidim::Conferences::Admin::UpdateConferenceSpeaker, Decidim::Conferences::Admin::UpdateMediaLink, Decidim::Conferences::Admin::UpdatePartner, Decidim::Conferences::Admin::UpdateRegistrationType, Debates::Admin::UpdateDebate, Debates::UpdateDebate, Initiatives::Admin::UpdateInitiative, Initiatives::Admin::UpdateInitiativeType, Initiatives::Admin::UpdateInitiativeTypeScope, Initiatives::Admin::UpdateInitiativesSettings, Meetings::Admin::UpdateAgenda, Meetings::Admin::UpdateMeeting, Meetings::Admin::UpdateRegistrations, ParticipatoryProcesses::Admin::UpdateParticipatoryProcess, ParticipatoryProcesses::Admin::UpdateParticipatoryProcessGroup, ParticipatoryProcesses::Admin::UpdateParticipatoryProcessStep, ParticipatoryProcesses::Admin::UpdateParticipatoryProcessType, Proposals::Admin::UpdateProposalState

Instance Method Summary collapse

Methods inherited from Decidim::Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(form, resource) ⇒ UpdateResource

Initializes the command.

Parameters:

  • form (Decidim::Form)

    the form object to update the resource.

  • resource (Decidim::Resource)

    the resource to update.



12
13
14
15
# File 'decidim-core/lib/decidim/commands/update_resource.rb', line 12

def initialize(form, resource)
  @form = form
  @resource = resource
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject

Updates the resource if valid.

Broadcasts :ok if successful, :invalid otherwise.



20
21
22
23
24
25
26
27
28
29
30
# File 'decidim-core/lib/decidim/commands/update_resource.rb', line 20

def call
  return broadcast(:invalid) if invalid?

  perform!
  broadcast(:ok, resource)
rescue ActiveRecord::RecordInvalid
  add_file_attribute_errors!
  broadcast(:invalid)
rescue Decidim::Commands::HookError
  broadcast(:invalid)
end