lib/ahoy.rb in ahoy_matey-4.2.1 vs lib/ahoy.rb in ahoy_matey-5.0.0

- old
+ new

@@ -19,17 +19,49 @@ require_relative "ahoy/visit_properties" require_relative "ahoy/engine" if defined?(Rails) module Ahoy + # activejob optional + autoload :GeocodeV2Job, "ahoy/geocode_v2_job" + mattr_accessor :visit_duration self.visit_duration = 4.hours mattr_accessor :visitor_duration self.visitor_duration = 2.years - mattr_accessor :cookies + def self.cookies=(value) + if value == false + if defined?(Mongoid::Document) && defined?(Ahoy::Visit) && Ahoy::Visit < Mongoid::Document + raise <<~EOS + This feature requires a new index in Ahoy 5. Set: + + class Ahoy::Visit + index({visitor_token: 1, started_at: 1}) + end + + Create the index before upgrading, and set: + + 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 + + mattr_reader :cookies self.cookies = true # TODO deprecate in favor of cookie_options mattr_accessor :cookie_domain @@ -90,9 +122,13 @@ mattr_accessor :logger def self.log(message) logger.info { "[ahoy] #{message}" } if logger + end + + def self.cookies? + cookies && cookies != :none end def self.mask_ip(ip) addr = IPAddr.new(ip) if addr.ipv4?