Class: Decidim::Elections::Election
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Elections::Election
- Includes:
- FilterableResource, Forms::HasQuestionnaire, HasAttachmentCollections, HasAttachments, HasComponent, Loggable, Publicable, Resourceable, Traceable, TranslatableResource
- Defined in:
- decidim-elections/app/models/decidim/elections/election.rb
Overview
The data store for an Election in the Decidim::Elections component. It stores a title, description and any other useful information to perform an election.
Class Method Summary collapse
Instance Method Summary collapse
-
#allow_resource_permissions? ⇒ Boolean
Public: Overrides the Resourceable concern method to allow setting permissions at resource level.
-
#blocked? ⇒ Boolean
Public: Checks if the election has a blocked_at value.
-
#finished? ⇒ Boolean
Public: Checks if the election finished.
-
#maximum_hours_before_start? ⇒ Boolean
Public: Checks if the election start_time is maximum some hours before than the present time.
-
#minimum_answers? ⇒ Boolean
Public: Checks if the number of answers are minimum 2 for each question.
-
#minimum_hours_before_start? ⇒ Boolean
Public: Checks if the election start_time is minimum some hours later than the present time.
-
#ongoing? ⇒ Boolean
Public: Checks if the election ongoing now.
-
#results? ⇒ Boolean
Public: Checks if the election results are present.
-
#results_published? ⇒ Boolean
Public: Checks if the election results are published and election finished.
-
#started? ⇒ Boolean
Public: Checks if the election started.
- #trustee_action_required? ⇒ Boolean
-
#valid_questions? ⇒ Boolean
Public: Checks if the election questions are valid.
-
#voting_period_status ⇒ Object
Public: Gets the voting period status of the election.
Methods included from Publicable
#previously_published?, #publish!, #published?, #unpublish!
Methods included from HasAttachments
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
49 50 51 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 49 def self.log_presenter_class_for(_log) Decidim::Elections::AdminLog::ElectionPresenter end |
.ransackable_scopes(_auth_object = nil) ⇒ Object
149 150 151 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 149 def self.ransackable_scopes(_auth_object = nil) [:with_any_date] end |
Instance Method Details
#allow_resource_permissions? ⇒ Boolean
Public: Overrides the Resourceable concern method to allow setting permissions at resource level
141 142 143 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 141 def true end |
#blocked? ⇒ Boolean
Public: Checks if the election has a blocked_at value
Returns a boolean.
136 137 138 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 136 def blocked? blocked_at.present? end |
#finished? ⇒ Boolean
Public: Checks if the election finished
Returns a boolean.
63 64 65 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 63 def finished? end_time < Time.current end |
#maximum_hours_before_start? ⇒ Boolean
Public: Checks if the election start_time is maximum some hours before than the present time
Returns a boolean.
84 85 86 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 84 def maximum_hours_before_start? start_time < (Time.zone.at(Decidim::Elections.start_vote_maximum_hours_before_start.hours.from_now)) end |
#minimum_answers? ⇒ Boolean
Public: Checks if the number of answers are minimum 2 for each question
Returns a boolean.
91 92 93 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 91 def minimum_answers? questions.any? && questions.all? { |question| question.answers.size > 1 } end |
#minimum_hours_before_start? ⇒ Boolean
Public: Checks if the election start_time is minimum some hours later than the present time
Returns a boolean.
77 78 79 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 77 def minimum_hours_before_start? start_time > (Time.zone.at(Decidim::Elections.setup_minimum_hours_before_start.hours.from_now)) end |
#ongoing? ⇒ Boolean
Public: Checks if the election ongoing now
Returns a boolean.
70 71 72 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 70 def ongoing? started? && !finished? end |
#results? ⇒ Boolean
Public: Checks if the election results are present
Returns a boolean.
105 106 107 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 105 def results? bb_tally_ended? || results_published? end |
#results_published? ⇒ Boolean
Public: Checks if the election results are published and election finished
Returns a boolean.
98 99 100 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 98 def results_published? bb_results_published? end |
#started? ⇒ Boolean
Public: Checks if the election started
Returns a boolean.
56 57 58 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 56 def started? start_time <= Time.current end |
#trustee_action_required? ⇒ Boolean
129 130 131 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 129 def trustee_action_required? bb_key_ceremony? || bb_tally_started? end |
#valid_questions? ⇒ Boolean
Public: Checks if the election questions are valid
Returns a boolean.
112 113 114 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 112 def valid_questions? questions.any? && questions.all?(&:valid_max_selection?) end |
#voting_period_status ⇒ Object
Public: Gets the voting period status of the election
Returns one of these symbols: upcoming, ongoing or finished
119 120 121 122 123 124 125 126 127 |
# File 'decidim-elections/app/models/decidim/elections/election.rb', line 119 def voting_period_status if finished? :finished elsif started? :ongoing else :upcoming end end |