Sha256: b3316db844c894315457d18a7ec2d8a2327de433c9f367627016a14ad5af71ed
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
module Workarea module CurrentTracking extend ActiveSupport::Concern include HttpCaching included do before_action :ensure_current_metrics helper_method :current_visit, :current_metrics delegate :current_metrics_id, :current_metrics_id=, :browser, to: :current_visit, allow_nil: true end def current_visit request.env['workarea.visit'] end def current_metrics current_visit.metrics end def update_tracking!(email: current_user&.email) if email.blank? cookies.delete(:email) elsif email != cookies.signed[:email] Metrics::User.find_or_initialize_by(id: email).merge!(current_visit&.metrics) cookies.permanent.signed[:email] = email end request.env['workarea.visit'] = Visit.new(request.env) end # This method is mostly for tests, but could surface in an implementation. # Since Rails doesn't set and load a session until needed, an initial # request won't have a session ID for `current_visit` to check when loading # metrics. This ensures there will be one. def ensure_current_metrics return if current_metrics_id.present? || http_caching? # This forces Rails to initialize the session, which provides an ID for metrics session.delete(:foo) self.current_metrics_id = session.id end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
workarea-core-3.5.0.beta.1 | app/controllers/workarea/current_tracking.rb |