Sha256: 5b34fbbfb477beb215e91afff23bc4b13b445ba99e677794f67478dcd40ac5a5
Contents?: true
Size: 695 Bytes
Versions: 21
Compression:
Stored size: 695 Bytes
Contents
module Spree class Tracker < Spree::Base TRACKING_ENGINES = %i(google_analytics segment).freeze enum engine: TRACKING_ENGINES after_commit :clear_cache validates :analytics_id, presence: true, uniqueness: { scope: :engine, case_sensitive: false } scope :active, -> { where(active: true) } def self.current(engine = TRACKING_ENGINES.first) tracker = Rails.cache.fetch("current_tracker/#{engine}") do send(engine).active.first end tracker.analytics_id.present? ? tracker : nil if tracker end def clear_cache TRACKING_ENGINES.each do |engine| Rails.cache.delete("current_tracker/#{engine}") end end end end
Version data entries
21 entries across 21 versions & 2 rubygems