Class: Decidim::Proposals::VoteProposal
- Inherits:
-
Rectify::Command
- Object
- Rectify::Command
- Decidim::Proposals::VoteProposal
- Defined in:
- decidim-proposals/app/commands/decidim/proposals/vote_proposal.rb
Overview
A command with all the business logic when a user votes a proposal.
Instance Attribute Summary collapse
-
#vote ⇒ Object
readonly
Returns the value of attribute vote.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(proposal, current_user) ⇒ VoteProposal
constructor
Public: Initializes the command.
Constructor Details
#initialize(proposal, current_user) ⇒ VoteProposal
Public: Initializes the command.
proposal - A Decidim::Proposals::Proposal object. current_user - The current user.
11 12 13 14 |
# File 'decidim-proposals/app/commands/decidim/proposals/vote_proposal.rb', line 11 def initialize(proposal, current_user) @proposal = proposal @current_user = current_user end |
Instance Attribute Details
#vote ⇒ Object (readonly)
Returns the value of attribute vote.
30 31 32 |
# File 'decidim-proposals/app/commands/decidim/proposals/vote_proposal.rb', line 30 def vote @vote end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid, together with the proposal vote.
-
:invalid if the form wasn’t valid and we couldn’t proceed.
Returns nothing.
22 23 24 25 26 27 28 |
# File 'decidim-proposals/app/commands/decidim/proposals/vote_proposal.rb', line 22 def call build_proposal_vote return broadcast(:invalid) unless vote.valid? vote.save! broadcast(:ok, vote) end |