Class Prompt
In: app/models/prompt.rb
Parent: ActiveRecord::Base

Methods

Included Modules

Constants::Prompts

Public Class methods

return fetched prompt and boolean true if new external fetch needed

[Source]

    # File app/models/prompt.rb, line 18
18:     def fetch(uid, ext_id, question, visit_id, prompts_shown)
19:       if uid == ANONYMOUS_USER_ID && prompts_shown < Param.value_named(PRIME_FOR, Default::PRIME_FOR).to_i
20:         # fetch a primed prompt
21:         fetch_first(uid, ext_id, visit_id, question, Param.value_named(PRIME_FOR, Default::PRIME_FOR).to_i, true)
22:       else
23:         fetch_first(uid, ext_id, visit_id, question, Param.refresh_question_after.to_i)
24:       end
25:     end

[Source]

    # File app/models/prompt.rb, line 49
49:     def fetch_more?(user_id, visit_id, question_id)
50:       count(:conditions => active_conditions(user_id, visit_id, question_id)) < MIN_AVAILABLE_PROMPTS
51:     end

[Source]

    # File app/models/prompt.rb, line 27
27:     def pairwise_fetch(question, ext_id, uid, visit_id, prompts_to_fetch = PROMPTS_PER_FETCH, prime = false)
28:       prompts, item_ids = Pairwise.prompt(question.question_id_ext, ext_id, prompts_to_fetch, prime)
29:       return false if prompts.to_a.empty?
30:       items = Item.all(:conditions => "item_id_ext IN (#{item_ids.flatten.join(',')})")
31:       items = item_ids.map { |el| el.map { |id| items.detect { |item| item.item_id_ext == id.to_i } } }
32:       prompt_to_return = nil
33:       Prompt.transaction do
34:         prompts.each do |id_ext|
35:           next if Prompt.exists?(:prompt_id_ext => id_ext)
36:           prompt = Prompt.create!(:prompt_id_ext => id_ext,
37:             :question_id => question.id,
38:             :user_id => uid,
39:             :visit_id => visit_id,
40:             :active => true
41:           )
42:           prompt.items << items.shift
43:           prompt_to_return = prompt if prompt_to_return.nil?
44:         end
45:       end
46:       prompt_to_return
47:     end

[Validate]