From d18d8f4374b877080e244958cfb8946278a9829d Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sun, 1 Oct 2023 18:17:36 -0700 Subject: [PATCH] Added Mongoid instructions --- lib/ahoy.rb | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/ahoy.rb b/lib/ahoy.rb index 88883888..1f87578f 100644 --- a/lib/ahoy.rb +++ b/lib/ahoy.rb @@ -32,16 +32,29 @@ module Ahoy def self.cookies=(value) if value == false - # TODO add Mongoid instructions - raise <<~EOS - This feature requires a new index in Ahoy 5. Create a migration: + if defined?(Mongoid::Document) && defined?(Ahoy::Visit) && Ahoy::Visit < Mongoid::Document + raise <<~EOS + This feature requires a new index in Ahoy 5. Set: - add_index :ahoy_visits, [:visitor_token, :started_at] + class Ahoy::Visit + index({visitor_token: 1, started_at: 1}) + end - Run it before upgrading, and set: + Create the index before upgrading, and set: - Ahoy.cookies = :none - EOS + Ahoy.cookies = :none + EOS + else + raise <<~EOS + This feature requires a new index in Ahoy 5. Create a migration with: + + add_index :ahoy_visits, [:visitor_token, :started_at] + + Run it before upgrading, and set: + + Ahoy.cookies = :none + EOS + end end @@cookies = value end