Class: Decidim::Elections::CastVotes
- Inherits:
-
Command
- Object
- Command
- Decidim::Elections::CastVotes
- Defined in:
- app/commands/decidim/elections/cast_votes.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(election, data, voter_uid) ⇒ CastVotes
constructor
A new instance of CastVotes.
Constructor Details
#initialize(election, data, voter_uid) ⇒ CastVotes
Returns a new instance of CastVotes.
6 7 8 9 10 |
# File 'app/commands/decidim/elections/cast_votes.rb', line 6 def initialize(election, data, voter_uid) @election = election @data = data @voter_uid = voter_uid end |
Instance Method Details
#call ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/commands/decidim/elections/cast_votes.rb', line 12 def call return broadcast(:invalid) unless election.ongoing? return broadcast(:invalid) if voter_uid.blank? return broadcast(:invalid) unless election.per_question? || voted_questions.count == election.questions.count return broadcast(:invalid) if voted_questions.blank? transaction do save_votes! end broadcast(:ok) rescue ActiveRecord::RecordInvalid, StandardError => e Rails.logger.error "#{e.class.name}: #{e.}" broadcast(:invalid) end |