Class: Decidim::Votings::CheckCensus

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/votings/check_census.rb

Overview

A command to check if census data is given

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#formObject (readonly)

Returns the value of attribute form.



23
24
25
# File 'app/commands/decidim/votings/check_census.rb', line 23

def form
  @form
end

#sessionObject (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

#callObject

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_censusObject



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