Module Systems::Visit
In: lib/systems/visit.rb

Methods

Public Instance methods

[Source]

   # File lib/systems/visit.rb, line 6
6:   def active_visit=(visit)
7:     session[:visit_id] = visit.id
8:     session[:visit_ip_country_code] = visit.ip_country_code
9:   end

[Source]

   # File lib/systems/visit.rb, line 2
2:   def assign_visit
3:     active_visit.update_attribute :user_id, current_user.id
4:   end

[Source]

    # File lib/systems/visit.rb, line 41
41:   def create_visit(locale = false)
42:     # if creating because of stale visit store last prompt in old visit
43:     save_prompt_to_visit if current_visit_id
44:     ip = request.env['HTTP_X_REAL_IP'] || request.env['REMOTE_ADDR']
45:     visit = ::Visit.new do |v|
46:       v.user_id = current_user.id if current_user
47:       v.host = request.env['HTTP_HOST']
48:       v.user_agent = request.env['HTTP_USER_AGENT']
49:       v.referrer = request.env['HTTP_REFERER']
50:       v.request_uri = request.env['REQUEST_URI']
51:     end
52:     visit = GeoIP.location(ip, visit)
53:     visit.locale = locale ? locale : assign_locale(visit)
54:     # assign the user an text experiment locale?
55:     visit.locale = session[:exp_locale] = (rand < Param.english_vary_prob) ? 'e2' : nil if visit.locale == Constants::Locales::DEFAULT
56:     # assign the user a prompts per question experiment
57:     visit.prompts_per_question = 4 + rand(7) # random length between 4 and 10
58:     visit.ip_address = (!visit.ip_country_code.nil? && Constants::Config::HASH_IP) ? Digest::SHA1.hexdigest(ip) : ip
59:     visit.save!
60:     self.active_visit = visit
61:     visit
62:   end

[Source]

    # File lib/systems/visit.rb, line 27
27:   def current_visit
28:     current_visit_id && ::Visit.find(current_visit_id)
29:   end

[Source]

    # File lib/systems/visit.rb, line 31
31:   def current_visit!
32:     (current_visit_id && ::Visit.find(current_visit_id)) || create_visit
33:   end

[Source]

    # File lib/systems/visit.rb, line 11
11:   def current_visit_id
12:     session[:visit_id]
13:   end

[Source]

    # File lib/systems/visit.rb, line 15
15:   def current_visit_id!
16:     session[:visit_id] || create_visit.id
17:   end

[Source]

    # File lib/systems/visit.rb, line 19
19:   def current_visit_ip_country_code
20:     session[:visit_ip_country_code]
21:   end

[Source]

    # File lib/systems/visit.rb, line 23
23:   def exp_locale
24:     session[:exp_locale]
25:   end

time out visit if updated_at + const > now

[Source]

    # File lib/systems/visit.rb, line 36
36:   def fresh_visit?
37:     visit = current_visit
38:     visit && visit.updated_at + Constants::Config::VISIT_STALE_AFTER > Time.now
39:   end

[Validate]