-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcontext.rb
More file actions
36 lines (30 loc) · 1.27 KB
/
context.rb
File metadata and controls
36 lines (30 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Flow
class Context
attr_reader :form, :journey, :confirmation_details_store
def initialize(form:, form_document:, store:)
@form = form
@answer_store = Store::SessionAnswerStore.new(store, form.id)
@confirmation_details_store = Store::ConfirmationDetailsStore.new(store, form.id)
@journey = Journey.new(answer_store: @answer_store, form_document:)
end
delegate :support_details, to: :form
delegate :step_by_id, :previous_step, :next_step_slug, :next_step, :can_visit?, :completed_steps, :all_steps, to: :journey
delegate :clear_stored_answer, :clear, :form_submitted?, :answers, :locales_used, to: :answer_store
delegate :save_submission_details,
:get_submission_reference,
:requested_email_confirmation?,
:clear_submission_details,
:save_copy_of_answers_preference,
:wants_copy_of_answers?,
:save_copy_of_answers_email_address,
:get_copy_of_answers_email_address,
to: :confirmation_details_store
def save_step(step, locale: :en, context: nil)
return false unless step.valid?(context)
answer_store.add_locale(locale)
step.save_to_store(answer_store)
end
private
attr_reader :answer_store
end
end