Class: Decidim::Amendable::UpdateDraft
- Defined in:
 - app/commands/decidim/amendable/update_draft.rb
 
Overview
A command with all the business logic when a user updates and amendment draft.
Instance Method Summary collapse
- 
  
    
      #call  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Executes the command.
 - 
  
    
      #initialize(form)  ⇒ UpdateDraft 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Public: Initializes the command.
 
Methods inherited from Command
call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events
Constructor Details
#initialize(form) ⇒ UpdateDraft
Public: Initializes the command.
form - A form object with the params.
      12 13 14 15 16 17 18  | 
    
      # File 'app/commands/decidim/amendable/update_draft.rb', line 12 def initialize(form) @form = form @amendment = form.amendment @amender = form.amender @emendation = form.emendation @user_group = Decidim::UserGroup.find_by(id: form.user_group_id) end  | 
  
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Decidim::Command
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
- 
:ok when everything is valid, together with the amend.
 - 
:invalid if the amendment is not a draft.
 - 
:invalid if the form is not valid or the amender is not the current user.
 
Returns nothing.
      27 28 29 30 31 32 33 34 35  | 
    
      # File 'app/commands/decidim/amendable/update_draft.rb', line 27 def call return broadcast(:invalid) unless form.valid? && amendment.draft? && amender == current_user transaction do update_draft end broadcast(:ok, @amendment) end  |