Class: Decidim::Votings::Census::Admin::CreateDatum
- Inherits:
-
Command
- Object
- Command
- Decidim::Votings::Census::Admin::CreateDatum
- Defined in:
- app/commands/decidim/votings/census/admin/create_datum.rb
Overview
A command with the business logic to create the datum for a dataset row.
Instance Attribute Summary collapse
-
#dataset ⇒ Object
readonly
Returns the value of attribute dataset.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
Instance Method Summary collapse
- #ballot_style_for_code(voting, code) ⇒ Object
-
#call ⇒ Object
Executes the command.
- #create_census_datum! ⇒ Object
-
#initialize(form, dataset) ⇒ CreateDatum
constructor
A new instance of CreateDatum.
Constructor Details
#initialize(form, dataset) ⇒ CreateDatum
Returns a new instance of CreateDatum.
10 11 12 13 |
# File 'app/commands/decidim/votings/census/admin/create_datum.rb', line 10 def initialize(form, dataset) @form = form @dataset = dataset end |
Instance Attribute Details
#dataset ⇒ Object (readonly)
Returns the value of attribute dataset.
27 28 29 |
# File 'app/commands/decidim/votings/census/admin/create_datum.rb', line 27 def dataset @dataset end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
27 28 29 |
# File 'app/commands/decidim/votings/census/admin/create_datum.rb', line 27 def form @form end |
Instance Method Details
#ballot_style_for_code(voting, code) ⇒ Object
48 49 50 |
# File 'app/commands/decidim/votings/census/admin/create_datum.rb', line 48 def ballot_style_for_code(voting, code) Decidim::Votings::Admin::BallotStyleByVotingCode.for(voting, code) end |
#call ⇒ Object
Executes the command. Broadcast this events:
-
:ok when everything is valid
-
:invalid when the form was not valid and could not proceed-
Returns nothing.
20 21 22 23 24 25 |
# File 'app/commands/decidim/votings/census/admin/create_datum.rb', line 20 def call return broadcast(:invalid) unless form.valid? create_census_datum! broadcast(:ok) end |
#create_census_datum! ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/commands/decidim/votings/census/admin/create_datum.rb', line 29 def create_census_datum! attributes = { hashed_in_person_data: form.hashed_in_person_data, hashed_check_data: form.hashed_check_data, full_name: form.full_name, full_address: form.full_address, postal_code: form.postal_code, mobile_phone_number: form.mobile_phone_number, email: form.email, decidim_votings_ballot_style_id: ballot_style_for_code(dataset.voting, form.ballot_style_code)&.id } Decidim::Votings::Census::Datum.create( dataset:, attributes: ) end |