Module Systems::PromptStore
In: lib/systems/prompt_store.rb

Methods

Attributes

current_prompt  [R] 
fetch_next  [RW] 
fetch_to_cache  [R] 
prompt_question  [RW] 
user_ext_id  [RW] 
user_id  [RW] 

Public Instance methods

[Source]

    # File lib/systems/prompt_store.rb, line 39
39:   def fetch_prompt
40:     prompt, @fetch_to_cache = ::Prompt.fetch(
41:       user_id,
42:       user_ext_id,
43:       prompt_question,
44:       current_visit_id!,
45:       prompts_shown
46:     )
47:     prompt
48:   end

[Source]

    # File lib/systems/prompt_store.rb, line 25
25:   def fetch_prompts
26:     self.active_prompt = @current_prompt
27:     self.next_prompt = next_prompt!
28:     if @fetch_to_cache == true && question_responses > 0
29:       # fetch for current if signalled this round and not first prompts
30:       @fetch_to_cache = false
31:       fetch_to_cache(prompt_question)
32:     elsif self.fetch_next ||= (question_responses > (refresh_question_after / 2))
33:       # fetch for next if not set false and more than half way through prompts
34:       self.fetch_next = false
35:       fetch_to_cache(next_question) if ::Prompt.fetch_more?(user_id, current_visit_id!, next_question.id)
36:     end
37:   end

[Source]

    # File lib/systems/prompt_store.rb, line 17
17:   def next_prompt
18:     session[:next_prompt]
19:   end

[Source]

    # File lib/systems/prompt_store.rb, line 13
13:   def next_prompt!
14:     prompts_left_for_question > 0 ? fetch_prompt : nil
15:   end

[Source]

    # File lib/systems/prompt_store.rb, line 21
21:   def next_prompt=(prompt)
22:     session[:next_prompt] = prompt
23:   end

[Source]

    # File lib/systems/prompt_store.rb, line 5
 5:   def update_prompts(prompt, increment = true, &blk)
 6:     @current_prompt = prompt || blk && blk.call
 7:     # check for stale prompts
 8:     @current_prompt = fetch_prompt unless current_prompt && Prompt.exists?(current_prompt.id)
 9:     increment_prompts_shown if increment && active_prompt != current_prompt
10:     fetch_prompts
11:   end

[Validate]