-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcontext.rb
More file actions
28 lines (22 loc) · 1.02 KB
/
context.rb
File metadata and controls
28 lines (22 loc) · 1.02 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
module Flow
class Context
attr_reader :form, :journey
def initialize(form:, 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:)
end
delegate :support_details, to: :form
delegate :find_or_create, :previous_step, :next_page_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, 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, :confirmation_details_store
end
end