Module: Decidim::Consultations::NeedsQuestion::InstanceMethods

Defined in:
app/controllers/concerns/decidim/consultations/needs_question.rb

Instance Method Summary collapse

Instance Method Details

#current_consultationObject

Public: Finds the current Consultation given this controller’s context.

Returns the current Consultation.



76
77
78
# File 'app/controllers/concerns/decidim/consultations/needs_question.rb', line 76

def current_consultation
  @current_consultation ||= current_question&.consultation || detect_consultation
end

#current_questionObject Also known as: current_participatory_space

Public: Finds the current Question given this controller’s context.

Returns the current Question.



34
35
36
# File 'app/controllers/concerns/decidim/consultations/needs_question.rb', line 34

def current_question
  @current_question ||= detect_question
end

#next_published_questionObject

same as next_question but for published questions only



59
60
61
62
63
# File 'app/controllers/concerns/decidim/consultations/needs_question.rb', line 59

def next_published_question
  return nil if current_published_question_index + 1 >= current_consultation_published_questions.size

  current_consultation_published_questions.at(current_published_question_index + 1)
end

#next_questionObject

Public: Finds the next Question in the Array of questions associated to the current_question’s consultation.

Returns the next Question in the Array or nil if out of bounds.



52
53
54
55
56
# File 'app/controllers/concerns/decidim/consultations/needs_question.rb', line 52

def next_question
  return nil if current_question_index + 1 >= current_consultation_questions.size

  current_consultation_questions.at(current_question_index + 1)
end

#previous_published_questionObject

same as previous_question but for published questions only



66
67
68
69
70
# File 'app/controllers/concerns/decidim/consultations/needs_question.rb', line 66

def previous_published_question
  return nil if (current_published_question_index - 1).negative?

  current_consultation_published_questions.at(current_published_question_index - 1)
end

#previous_questionObject

Public: Finds the previous Question in the Array of questions associated to the current_question’s consultation.

Returns the previous Question in the Array or nil if out of bounds.



42
43
44
45
46
# File 'app/controllers/concerns/decidim/consultations/needs_question.rb', line 42

def previous_question
  return nil if (current_question_index - 1).negative?

  current_consultation_questions.at(current_question_index - 1)
end