Class: Decidim::Votings::CheckCensus
- Inherits:
-
Command
- Object
- Command
- Decidim::Votings::CheckCensus
- Defined in:
- app/commands/decidim/votings/check_census.rb
Overview
A command to check if census data is given
Instance Attribute Summary collapse
-
#form ⇒ Object
readonly
Returns the value of attribute form.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
- #check_census ⇒ Object
-
#initialize(form) ⇒ CheckCensus
constructor
A new instance of CheckCensus.
Constructor Details
#initialize(form) ⇒ CheckCensus
Returns a new instance of CheckCensus.
7 8 9 |
# File 'app/commands/decidim/votings/check_census.rb', line 7 def initialize(form) @form = form end |
Instance Attribute Details
#form ⇒ Object (readonly)
Returns the value of attribute form.
23 24 25 |
# File 'app/commands/decidim/votings/check_census.rb', line 23 def form @form end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
23 24 25 |
# File 'app/commands/decidim/votings/check_census.rb', line 23 def session @session end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcast this events:
-
:ok when census is found
-
:invalid when the form is not valid
-
:not_found when census is not found
Returns nothing.
17 18 19 20 21 |
# File 'app/commands/decidim/votings/check_census.rb', line 17 def call return broadcast(:invalid) unless form.valid? check_census end |
#check_census ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'app/commands/decidim/votings/check_census.rb', line 25 def check_census datum = Decidim::Votings::Census::Datum.find_by(dataset: form.current_participatory_space.dataset, hashed_check_data: form.hashed_check_data) if datum broadcast(:ok, datum) else broadcast(:not_found) end end |